Is it possible to get the equivalent of the "memory address" of a .net object?

We run our own serialization tool in our project and are faced with the need to uniquely identify each object using a primitive value type that can be used as a synonym for its โ€œidentityโ€. The value should not have any meaning or organization, but simply because it is unique and constant, at least throughout the serialization process. Ideally .net would internally support a unique and persistent object identifier that we could store as an object identifier. I know that every object has a GetHashCode method, but we are not sure about the value of global uniqueness. Another criterion for accessing this identifier is that the method must be very efficient.

I looked at GetHashCode , a garbage collector and sorting ideas, haven't come up with anything yet.

+4
source share
1 answer

You are looking for an ObjectIDGenerator class that does exactly what you are trying to do.

+4
source

Source: https://habr.com/ru/post/1439827/


All Articles