Export (0) Print
Expand All

Expression.Field Method (Expression, String)

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

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

static member Field : 
        expression:Expression * 
        fieldName:string -> MemberExpression

Parameters

expression
Type: System.Linq.Expressions.Expression

An Expression whose Type contains a field named fieldName. This can be null for static fields.

fieldName
Type: System.String

The name of a field to be accessed.

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 FieldInfo that represents the field denoted by fieldName.

ExceptionCondition
ArgumentNullException

expression or fieldName is a null reference (Nothing in Visual Basic).

ArgumentException

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

The Type property of the resulting MemberExpression is equal to the FieldType property of the FieldInfo that represents the field denoted by fieldName.

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

The following code example shows how to create an expression that represents accessing a field.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft