How to get the property name

advertisements

How do I make the method shown below to return the name of the property

public class MyClass
{
private string _MyProperty = "TEST";

public string MyProperty
{
    get { return _MyProperty; }
    set { _MyProperty = value; }
}

public string GetName()
{
    return _MyProperty;  // <- should return "MyProperty";
}

}

i don't wana use return "MyProperty" so any alternative?


Here's an similar question and answer that uses an Expression for creating a NameOf<> operator.