Expression.Field Metoda

Definicja

Tworzy obiekt MemberExpression reprezentujący dostęp do pola.

Przeciążenia

Field(Expression, FieldInfo)

Tworzy obiekt MemberExpression reprezentujący dostęp do pola.

Field(Expression, String)

Tworzy obiekt MemberExpression reprezentujący dostęp do pola o nazwie pola.

Field(Expression, Type, String)

Tworzy obiekt MemberExpression reprezentujący dostęp do pola.

Field(Expression, FieldInfo)

Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs

Tworzy obiekt MemberExpression reprezentujący dostęp do pola.

public:
 static System::Linq::Expressions::MemberExpression ^ Field(System::Linq::Expressions::Expression ^ expression, System::Reflection::FieldInfo ^ field);
public static System.Linq.Expressions.MemberExpression Field (System.Linq.Expressions.Expression expression, System.Reflection.FieldInfo field);
public static System.Linq.Expressions.MemberExpression Field (System.Linq.Expressions.Expression? expression, System.Reflection.FieldInfo field);
static member Field : System.Linq.Expressions.Expression * System.Reflection.FieldInfo -> System.Linq.Expressions.MemberExpression
Public Shared Function Field (expression As Expression, field As FieldInfo) As MemberExpression

Parametry

expression
Expression

Element , Expression aby ustawić właściwość równą Expression . W przypadku static elementu (Shared w języku Visual Basic expression ) musi mieć wartość null.

field
FieldInfo

Właściwość , FieldInfo aby ustawić właściwość równą Member .

Zwraca

WłaściwośćMemberExpression, która ma właściwość równą MemberAccessNodeType i Expression właściwości i Member ustawioną na określone wartości.

Wyjątki

field to null.

-lub-

Pole reprezentowane przez element nie static jest (Shared w Visual Basic) i expression ma wartość null.field

expression. Typ nie można przypisać do deklarowanego typu pola reprezentowanego przez element field.

Uwagi

Właściwość Type wynikowej MemberExpression jest równa FieldType właściwości .field

Dotyczy

Field(Expression, String)

Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs

Tworzy obiekt MemberExpression reprezentujący dostęp do pola o nazwie pola.

public:
 static System::Linq::Expressions::MemberExpression ^ Field(System::Linq::Expressions::Expression ^ expression, System::String ^ fieldName);
public static System.Linq.Expressions.MemberExpression Field (System.Linq.Expressions.Expression expression, string fieldName);
static member Field : System.Linq.Expressions.Expression * string -> System.Linq.Expressions.MemberExpression
Public Shared Function Field (expression As Expression, fieldName As String) As MemberExpression

Parametry

expression
Expression

Obiekt, którego ExpressionType zawiera pole o nazwie fieldName. Może to mieć wartość null dla pól statycznych.

fieldName
String

Nazwa pola do uzyskania dostępu.

Zwraca

WłaściwośćMemberExpression, która ma właściwość równą MemberAccessNodeType , Expression właściwość ustawiona na expression, a Member właściwość ustawiona na FieldInfo wartość , która reprezentuje pole oznaczone przez fieldName.

Wyjątki

expression lub fieldName to null.

W elemecie expressionnie zdefiniowano żadnego pola o nazwie fieldName . Wpisz lub jego typy podstawowe.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć wyrażenie reprezentujące dostęp do pola.

// Add the following directive to your file:
// using System.Linq.Expressions;

class TestFieldClass
{
    int sample = 40;
}

static void TestField()
{
    TestFieldClass obj = new TestFieldClass();

    // This expression represents accessing a field.
    // For static fields, the first parameter must be null.
    Expression fieldExpr = Expression.Field(
        Expression.Constant(obj),
        "sample"
    );

    // The following statement first creates an expression tree,
    // then compiles it, and then runs it.
    Console.WriteLine(Expression.Lambda<Func<int>>(fieldExpr).Compile()());
}

// This code example produces the following output:
//
// 40
' Add the following directive to your file:
' Imports System.Linq.Expressions

Class TestFieldClass
    Dim sample As Integer = 40
End Class

Sub TestField()

    Dim obj As New TestFieldClass()

    ' This expression represents accessing a field.
    ' For static fields, the first parameter must be Nothing.
    Dim fieldExpr As Expression = Expression.Field(
          Expression.Constant(obj),
          "sample"
      )

    ' The following statement first creates an expression tree,
    ' then compiles it, and then runs it.
    Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(fieldExpr).Compile()())
End Sub

' This code example produces the following output:
'
' 40

Uwagi

Właściwość Type wynikowa MemberExpression jest równa FieldType właściwości elementu reprezentującego FieldInfo pole oznaczone przez fieldName.

Ta metoda wyszukuje expression. Wpisz i jego typy podstawowe dla pola o nazwie fieldName. Pola publiczne są preferowane w przypadku pól innych niż publiczne. Jeśli zostanie znalezione pasujące pole, ta metoda zostanie przekazywana expression , a FieldInfo ta metoda reprezentuje to pole do Field.

Dotyczy

Field(Expression, Type, String)

Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs
Źródło:
MemberExpression.cs

Tworzy obiekt MemberExpression reprezentujący dostęp do pola.

public:
 static System::Linq::Expressions::MemberExpression ^ Field(System::Linq::Expressions::Expression ^ expression, Type ^ type, System::String ^ fieldName);
public static System.Linq.Expressions.MemberExpression Field (System.Linq.Expressions.Expression expression, Type type, string fieldName);
public static System.Linq.Expressions.MemberExpression Field (System.Linq.Expressions.Expression? expression, Type type, string fieldName);
static member Field : System.Linq.Expressions.Expression * Type * string -> System.Linq.Expressions.MemberExpression
Public Shared Function Field (expression As Expression, type As Type, fieldName As String) As MemberExpression

Parametry

expression
Expression

Obiekt zawierający pole. Może to mieć wartość null dla pól statycznych.

type
Type

Element Type , który zawiera pole.

fieldName
String

Pole, do których ma być uzyskiwany dostęp.

Zwraca

Utworzony element MemberExpression.

Dotyczy