views:

111

answers:

4

Possible Duplicate:
Anonymous Types - Are there any distingushing characteristics?

Can't find suitable property.

if(new {a = 2, b= "z"}.GetType()...)

what to put instead of ...?

A: 

Have you tried outputting new { a = 2, b = "z" }.GetType() to get a value to compare with? If not, this is what I'd do first.

var t = new { a = 2, b = "z" }.GetType();

var c = 2; // set a breakpoint on this line, and see what t contains
Tomas Lycken
A: 

Anonymous types are reference types that derive directly from object. The compiler gives them a name although your application cannot access it. From the perspective of the common language runtime, an anonymous type is no different from any other reference type, except that it cannot be cast to any type except for object.

Pranay Rana
A: 

Anonymous class will include the name AnonymousType, they wont have a namespace or a declaring type. You might use that to see if it's anonymous. Although I'm not sure how safe it is...

var t = new { a = 2, b = "z" }.GetType();
bool isAnonymous = t.Namespace == null && t.DeclaringType == null;
simendsjo
A: 

Except for the weird name starting with <> and containing AnonymousType (in C#, as in VB it starts with VB$) there's not much to be tested. I wouldn't bet on name testing, however...

Sorin Comanescu