Reputation: 217
I'm using FastMember for an alternative to reflection. In the source, I see there is a unit test for anonymous type support, but I'm getting a NotSupportedException when I attempt to TypeMember.CreateNew() for an anonymous type. Are they not supported?
Upvotes: 2
Views: 232
Reputation: 1795
Very old question but I just had the same doubt and you can simply do:
var anon = new
{
Prop1 = "a",
Prop2 = "b"
};
MemberSet members =
TypeAccessor
.Create(anon.GetType())
.GetMembers();
Upvotes: 0
Reputation: 15916
They are supported but not with TypeMember
- you should be using ObjectAccessor
instead like:
var obj = new {A = 123, B = "def"};
var accessor = ObjectAccessor.Create(obj);
Assert.AreEqual(123, accessor["A"]);
Upvotes: 0