Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is System.Linq.Expressions.FieldExpression defined?

Observe the following code:

static void Main(string[] args)
{
    var f = new Foo();
    Expression<Func<string>> x = () => f.Bar;
    MemberExpression y = (MemberExpression) x.Body;
    Expression z = y.Expression;
}

class Foo
{
    public string Bar { get; set; }
}

When I break and observe z, I can see that it has a base type of System.Linq.Expressions.Expression and actual type of System.Linq.Expressions.FieldExpression.

enter image description here

The problem is that I cannot explicitly cast it as the latter:

System.Linq.Expressions.FieldExpression z = y.Expression;

I'm getting an error

The type or namespace name 'FieldExpression' does not exist in the namespace 'System.Linq.Expressions'.

Indeed, it's nowhere to be found in the API documentation.

There are references to it out there, but the ones I've looked into have lead to broken links or similar:

https://csharpdoc.hotexamples.com/class/System.Linq.Expressions/FieldExpression https://www.fuget.org/packages/System.Linq.Expressions/4.3.0/lib/netstandard1.6/System.Linq.Expressions.dll/System.Linq.Expressions/FieldExpression

Can someone please tell me what is going on?

like image 825
rory.ap Avatar asked Sep 06 '25 03:09

rory.ap


1 Answers

It's an internal type, derived from MemberExpression. There's nothing particularly unexpected about a public class having an internal class deriving from it.

like image 156
Jon Skeet Avatar answered Sep 07 '25 19:09

Jon Skeet