As far as I remember, there is a [CompilerGenerated] marker ... 2 sec.
Plus the name will be fancy, and it will be a generic type; -p
Actually, for "get", etc. I would probably just use the static (non-expanding) method.
If you just need a way to get the value from an anon-type instance (at a later point in time), perhaps the best option is lambda - note that you need a few tricks to remove this:
static void Main() { var foo = new { name = "John", age = 25 }; var func = Get(foo, x => x.age); var bar = new { name = "Marc", age = 30 }; int age = func(bar); }
(edit the comment). Definitely this attribute:
var foo = new { A = "B" }; Type type = foo.GetType(); CompilerGeneratedAttribute attrib = (CompilerGeneratedAttribute) Attribute.GetCustomAttribute( type, typeof(CompilerGeneratedAttribute)); // non-null, therefore is compiler-generated
Marc Gravell Nov 24 '08 at 19:23 2008-11-24 19:23
source share