Expression.Property Method (Expression, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates a MemberExpression that represents accessing a property.

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

Public Shared Function Property (
	expression As Expression,
	propertyName As String
) As MemberExpression


Type: System.Linq.Expressions.Expression

An Expression whose Type contains a property named propertyName. This can be null for static properties.

Type: System.String

The name of a property 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 PropertyInfo that represents the property denoted by propertyName.

Exception Condition

expression or propertyName is null.


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

The Type property of the resulting MemberExpressionis equal to the PropertyType property of the PropertyInfo that represents the property denoted by propertyName.

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

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

' Add the following directive to your file:
' Imports System.Linq.Expressions  

Class TestPropertyClass
    Public Property Sample As Integer
End Class

Sub TestProperty()

    Dim obj As New TestPropertyClass()
    obj.Sample = 40

    ' This expression represents accessing a property.
    ' For static properties, the first parameter must be Nothing.
    Dim propertyExpr As Expression = Expression.Property(

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

' This code example produces the following output:
' 40

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top