Home > Software engineering >  Where is System.Linq.Expressions.FieldExpression defined?
Where is System.Linq.Expressions.FieldExpression defined?

Time:04-04

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 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?

CodePudding user response:

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

  • Related