Hi Patrice,
thanks for taking the time to reply, but I'm afraid you've missed the
question completely!
IMO the first step would be to explain what you'll do with this
information.
I guess that would require a lot of writing, but basically, I'm writing a
QueryProvider that allows expressions against IQueryable business models to
be translated/mapped to internal entities exposed by LINQ to SQL/EF (which
is the DAL). Because I need to trim for security on the result set (once
enumeration occours - and this can't be done in DB), I need to know whether
the resulting type is a projection or not. If it's a projection, I'll have
to translate the Select() expression to a standard Select() expression, and
use the lambda (that holds the projection of T) to yield the correct type
back when enumerating .. long story, as you can imagine, but it's working
nicely, and I'm adding support for compiled queries and so forth.
I annotate the business models (and their members) with attributes to map to
the correct internal entity type (and member, if there's an mismatch). When
I translate the incoming expression tree, the goal is to end up with the
similar expression targetting LINQ to SQL/EF - and, like I said, it's
working nicely, is very flexible and supports a wide range of features
already.
Basically I'm on top of it, except for the small part of recognizing the
anonymous types, however, I could just go the other way around and recognize
"known" types, such as "strings, structs (value types), and business
models"; if the type differs from that, it's a projection - end result is
the same, and I guess, better.
Ultimately an anonymous type is just a type whose name has been
automatically assigned by the compiler so for now I don't see what you'll
want to do once you know that (and anonymous types are unrelated with the
result of a projection, they can be used for other purpose and a
projection could be of a well known type).
I'm well aware of how anonymous types works, who create them and so forth,
and I was simply asking if there was a property or the like on a reflection
type that I had missed (I guess that was also the essense of my question).
Do you want to find out out the type of elements returned by a query ?
No, that information is readily available from the expression tree (as
generic parameters to IEnumerable<T> or IEnumerable<IGrouping<T, K>> etc.).