Well, I am not alone who is being sick of magical strings which are constantly used just to do data binding -- see:
http://stackoverflow.com/questions/1329138/how-to-make-databinding-type-safe-and-support-refactoring
However I am concerned with performance of this solution and much more typing -- each time you would like to use nameof you have to type a lambda. So I am thinking of more brute-force method -- writing a function nameof and external program, that will change each .cs file before it is compiled.
public string nameof<T>(T obj,string name = null)
{
return name;
}
You would use it this way
nameof(the_object.MyProperty);
The key lies in external program helping nameof -- it would search for any call of the nameof, and simply replace
nameof(X.Y.Z)
or
nameof(X.Y.Z,"s")
into
nameof(X.Y.Z,"Z")
My question is -- what limitations, pitfalls of this approach do you see? Or maybe .Net 5.0 with built-in nameof will be shipped next week, so it make no sense to start writing a program for it? ;-)
Thank you in advance for your thoughts, recommendations, and so on.