0

is there a reliable way to detect if the target of something like someQueryable.Select(x => new {Name = x.FirstName}) is an anonymous class?

I'm working on an IQueryable implementation and it would be very handy to detect anonymous class selects, as as long as the values just get selected into an anonymous class I can just handle them as alias names for further operations.

The most distinct property of an anonymous type I found so far is the NewExpression.Members collection which lists constructor argument <=> member relations.

If this is set I know exactly which member field is an alias to each constructor argument, but as long as non anonymous types can also set NewExpression.Members I can never be sure value didn't get modified in the constructor or the getter itself.

Or is there any other way which is more reliable that "good guess"?

Thanks

Fionn
  • 10,975
  • 11
  • 54
  • 84

0 Answers0