Click or drag to resize
DigitalRuneObjectHelperGetPropertyNameT Method (ExpressionFuncT)
Retrieves the name of a property identified by a lambda expression.

Namespace: DigitalRune
Assembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax
public static string GetPropertyName<T>(
	Expression<Func<T>> expression
)

Parameters

expression
Type: System.Linq.ExpressionsExpressionFuncT
A lambda expression selecting the property.

Type Parameters

T
The type of the property.

Return Value

Type: String
The name of the property accessed by expression.
Exceptions
ExceptionCondition
ArgumentNullExceptionexpression is .
ArgumentExceptionexpression does not represent an expression accessing a property.
Remarks
It is recommended to use this method to access the name of a property instead of using hard-coded string values.
Examples
The following example shows how to retrieve the name of a property as a string.
C#
class MyClass
{
  public int MyProperty { get; set; }
}

...

MyClass myClass = new MyClass();

// The following line retrieves the property name as a string.
string propertyName = ObjectHelper.GetPropertyName(() => myClass.MyProperty);
See Also