¿Cómo puedo encontrar todas las referencias de cadena del objeto? [duplicar]

Posible duplicado:
Seguimiento de todas las referencias de objetos en C #

Las cadenas son tipos de referencia. They have two parts; an object y reference to object. Por ejemplo;

string str1 = "Soner";
string str2 = str1;

str1 y str2 are references to same object, "Soner" is an object. Is there any way to find all references point to the same object? In this case, I try to find str1 y str2 solo usando "Soner" objeto?

Of course, I didn't know also how to access to string object without any reference to it. I want to know if there is a way.

preguntado el 24 de diciembre de 12 a las 12:12

Do you mean you want to find all variables that reference a specific object in runtime at a specific point in time? -

@Oded Nearly, I want to find all references to the same object. As you say, I could be only for runtime right? -

mirar De Mark Gravell https://www.youtube.com/watch?v=xB-eutXNUMXJtA&feature=youtu.be a la misma pregunta. He says you can gatter all references of an object using SOSAssist. -

And don't forget that strings are immutable and when you change them they are not the old object anymore. -

@mahditahsildari Of course, but in my case there is no string changing. -

1 Respuestas

There isn't any built in way to get all the refercences to an object at runtime within your CLR process. The GC does not give any information about object references.

Everything you could do is building custom "tracker" that keeps references to the objects after they've been added explicitly. Jon Skeet describes the basic idea here.

contestado el 23 de mayo de 17 a las 13:05

But, If I try s.GetHashCode() , r.GetHashCode() y RuntimeHelpers.GetHashCode("Soner"). First and second gave me same result but third didn't. - Soner Gonül

Ir con RuntimeHelpers.GetHashCode if you want to use the hashcode to track the objects yourself, since GetHashCode can be overridden by classes (System.String does that) resulting in custom implementation. See mi pasta para un ejemplo - Guiones de juego

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.