dotnet / dotnet/dotnet-api-docs

Static properties/fields using Expression.PropertyOrField

Open
#2,449 1 comment 0 reactions 0 assignees View on GitHub
area-System.Linq.Expressions Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

The documentation of the [`expression` parameter](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.propertyorfield#parameters) at [**Expression.PropertyOrField**](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.propertyorfield) states:

> This can be null for static members.

However, this is incorrect, as the documentation itself notes (under [**Exceptions**](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.propertyorfield#exceptions)) than an `ArgumentNullException` is thrown if `expression` is `null`.

It would seem that the only way to create a `MemberExpression` of a static field or property would be to use the [**MakeMemberAccess**](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.makememberaccess) factory method.

(https://stackoverflow.com/questions/17700455/can-expression-propertyorfield-be-used-to-access-a-static-property-or-field)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.