I am trying to get something similar to nameof(property) but including the path of the object it belongs to (and including higher level objects if they exist).
Lets say
public class ClassA(){
public ClassB { get; set;}
public ClassC { get; set;}
public ClassD { get; set;}
}
public ClassB(){
public string PropOfB { get; set; }
}
public ClassC(){
public string PropOfC { get; set; }
}
public ClassD(){
public string PropOfD { get; set; }
public ClassC ClassC { get; set; }
}
I have a method that returns nameof(property)
, but if I run into (PropOfC)
, I need a little more to determine which PropOfC I am getting returned.
I would like my result to be ClassA.ClassD.ClassC.PropOfC
I've looked at the answers to: Using reflection in C# to get properties of a nested object
Get Object value by string path
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/reflection
but these are if you have the object instance on the highest level.
The things I've tried (I am not able to look at them atm) all return NameSpace.ClassC.PropOfC
, and that doesn't help for this situation.
I am doing this because of the need to show where in the object the specific prop that needs to be reviewed is without having to hard code the responses.
I am stuck in the mud on this.