I'm trying to create a dynamic type in .Net.
I want to get a group of Key Value pairs from a DB table and create a new type of object that has a Property-Value relation.
Example: If I have a row in the table t开发者_运维问答hat has a field that says "Licence Plate" and the other field says "STKOVFL". I want to create an object that has a Property called Licence_Plate, and returns the String "STKOVFL".
Is it possible with introspection?
Best Regards!
Here is an very simple example of what your trying to do.
public class ExampleD : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = null;
if (binder.Name == "Licence_Plate")
result = "STKOVFL";
return result != null;
}
}
Console.WriteLine(d.License_Plate);
精彩评论