What I have:
public class ClassA: Class C
{
public string Prop1 {get;set;}
public ClassB Prop2 {get; set;}
}
public class ClassB: Class C
{
public int Prop3 {get; set;}
}
I want a method like nameof() which will behave something like this:
string myString = GetPropertyName(ClassA.Prop2.Prop3);
myString:
"ClassB\Prop2\Prop3"
public string GetPropertyName(<no idea what the parameter type should be>)
{
I cant still fiqure out how to get the full name and how to put / in between, but what to put
as parameter so that I can put the properties as parameters like we do in name of?
}
If performance is not taken into consideration you can try to look into expression trees. Starting point would be something like this:
This can be improved but there are many downsides to this solution - some of compile time safety is lost (see the exceptions), performance (though you can try cache some results, but it is separate hard topic and it still will not be anywhere near the
nameof). Another option would be to look into IL weaving(for example with Fody), but not sure where you can go with it.