dotnet / dotnet/dotnet-api-docs
Static properties/fields using Expression.PropertyOrField
- 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
Assessment
This issue has not been assessed yet.