Probably impossible but is worth a shot...
"nameof" is an amazing idea which would be good to replicate in previous versions even if partially.
I am particularly interested in public property names like:
public class MyClass
{
public SomeType Myproperty {get;set;}
}
static Main()
{
MyClass myClass = new MyClass();
Console.WriteLine(Utilities.NameOf(myClass.MyProperty)); //Writes "MyProperty".
Console.ReadKey();
}
Is there a way to do this (maybe through reflection etc.)? If we could do this, it would also prepare our code for when we upgrade to C#6 in the future by simply replacing Utilities.NameOf with nameof.
Aucun commentaire:
Enregistrer un commentaire