Reputation: 1893
I have following code:
Type type = Type.GetTypeFromProgID("interopTypeName");
dynamic obj = Activator.CreateInstance(type);
string propertyName = "somePropertyName";
// how to get somePropertyName from obj?
It is possible to do it without dynamic. Here is Marc Gravell's solution how to do it. However it is interesting if it is possible to do it using dynamic.
Upvotes: 1
Views: 547
Reputation: 31799
Mark Gravell has an opensource project called FastMember that makes it easy to access properties using the code the api dynamic generates.
var wrapped = ObjectAccessor.Create(obj);
var result = wrapped[somePropertyName];
Upvotes: 1