Export (0) Print
Expand All

Expression.PropertyOrField Method

Creates a MemberExpression that represents accessing a property or field given the name of the property or field.

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

public static MemberExpression PropertyOrField(
	Expression expression,
	string propertyOrFieldName


Type: System.Linq.Expressions.Expression

An Expression whose Type contains a property or field named propertyOrFieldName.

Type: System.String

The name of a property or field.

Return Value

Type: System.Linq.Expressions.MemberExpression
A MemberExpression that has the NodeType property equal to MemberAccess, the Expression property set to expression, and the Member property set to the PropertyInfo or FieldInfo that represents the property or field denoted by propertyOrFieldName.


expression or propertyOrFieldName is null.


No property or field named propertyOrFieldName is defined in expression.Type or its base types.

The Type property of the resulting MemberExpression is equal to the PropertyType or FieldType properties of the PropertyInfo or FieldInfo, respectively, that represents the property or field denoted by propertyOrFieldName.

This method searches expression.Type and its base types for a property or field that has the name propertyOrFieldName. Public properties and fields are given preference over non-public properties and fields. Also, properties are given preference over fields. If a matching property or field is found, this method passes expression and the PropertyInfo or FieldInfo that represents that property or field to Property or Field, respectively.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

Community Additions

© 2014 Microsoft