I know I could have an attribute but that\'s more work than I want to go to... and not general enough.
I want to do something like
class Whotsit
{
It is possible (without reflection) but only with latest C# 3.0
quick & very very dirty
class Program
{
static void Main()
{
string propertyName = GetName(() => AppDomain.CurrentDomain);
Console.WriteLine(propertyName); // prints "CurrentDomain"
Console.ReadLine();
}
public static string GetName(Expression<Func<object>> property)
{
return property.Body.ToString().Split('.').Last();
}
}
Update: I've just realized that Jon Skeet (anyone surprised? :) has covered this possibility already but I'll keep my answer here just in case someone is interested in some example to start with.