| ObjectHelperGetPropertyNameT Method (ExpressionFuncT) |
Retrieves the name of a property identified by a lambda expression.
Namespace: DigitalRuneAssembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax public static string GetPropertyName<T>(
Expression<Func<T>> expression
)
Public Shared Function GetPropertyName(Of T) (
expression As Expression(Of Func(Of T))
) As String
public:
generic<typename T>
static String^ GetPropertyName(
Expression<Func<T>^>^ expression
)
static member GetPropertyName :
expression : Expression<Func<'T>> -> string
Parameters
- expression
- Type: System.Linq.ExpressionsExpressionFuncT
A lambda expression selecting the property.
Type Parameters
- T
- The type of the property.
Return Value
Type:
StringThe name of the property accessed by
expression.
Exceptions 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.
class MyClass
{
public int MyProperty { get; set; }
}
...
MyClass myClass = new MyClass();
string propertyName = ObjectHelper.GetPropertyName(() => myClass.MyProperty);
See Also