MemberExpression Class (System.Linq.Expressions) (original) (raw)

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents accessing a field or property.

public ref class MemberExpression : System::Linq::Expressions::Expression
public ref class MemberExpression sealed : System::Linq::Expressions::Expression
public class MemberExpression : System.Linq.Expressions.Expression
public sealed class MemberExpression : System.Linq.Expressions.Expression
type MemberExpression = class
    inherit Expression
Public Class MemberExpression
Inherits Expression
Public NotInheritable Class MemberExpression
Inherits Expression

Inheritance

Examples

The following example creates a MemberExpression that represents getting the value of a field member.

class Animal
{
    public string species;
}

public static void CreateFieldExpression()
{
    Animal horse = new Animal();

    // Create a MemberExpression that represents getting
    // the value of the 'species' field of class 'Animal'.
    System.Linq.Expressions.MemberExpression memberExpression =
        System.Linq.Expressions.Expression.Field(
            System.Linq.Expressions.Expression.Constant(horse),
            "species");

    Console.WriteLine(memberExpression.ToString());

    // This code produces the following output:
    //
    // value(CodeSnippets.FieldExample+Animal).species
}
Class Animal
    Dim species As String
End Class

Shared Sub CreateFieldExpression()
    Dim horse As New Animal

    ' Create a MemberExpression that represents getting
    ' the value of the 'species' field of class 'Animal'.
    Dim memberExpression As System.Linq.Expressions.MemberExpression = _
        System.Linq.Expressions.Expression.Field( _
            System.Linq.Expressions.Expression.Constant(horse), _
            "species")

    Console.WriteLine(memberExpression.ToString())

    ' This code produces the following output:
    '
    ' value(ExpressionVB.FieldExample+Animal).species
End Sub

Remarks

Use the Field, Property or PropertyOrField factory methods to create a MemberExpression.

The value of the NodeType property of a MemberExpression is MemberAccess.

Applies to