If I understand correctly, you have an object with a lot of properties, then you can make a method in this class that will "scan" all properties using C # reflection.
Create such a method in the class of the object you want to parse:
string PropertyThatHasCertainValue(object Value) { Type myType = this.GetType(); while(myType != typeof(object)) { foreach (PropertyInfo property_info in myType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (object.Equals(property_info.GetValue(this, null), Value)) { return property_info.Name; } } myType = myType.BaseType; } return "No property has this value"; }
Then in the watch add the following hours:
MyObjectInstance.PropertyThatHasCertainValue(ValueYouAreLookingFor)
Please note that you can use something else, but object as a parameter to simplify input in hours, but VS watch Window you can easily enter not only numbers and strings, but also enumerations. Visual Studio watches are extremely powerful, they will almost always correctly evaluate expression.
I added a while loop to jump recursively through all parents. BindingFlags.NonPublic will return all private and protected methods of the class, but not private methods of the base classes. Moving through all the base classes until it hits the object will solve this.
source share