Let's say I have the following class:
class Person
{
public String Name { get; set; }
public String Address { get; set; }
}
And then I create a dynamic object, like this:
dynamic person = new ExpandoObject();
person.Name = "Henrik";
person.Address = "Home";
person.Age = 100;
Now, is it possible in any (preferrably simple) way to convert the created object into an object of (a subclass of) the class Person? Doing this doesn't work:
var p = (Person)person;
since the person object is not related to the class Person in any way, it just happens to contain all the properties of the class Person. But is it possible to make the conversion work anyway, in a simple and generic way? Ideally, I would like to be able to cast my person object into a subclass of Person, which contains (obviously) all the properties of Person, in addition to (in this example) the new property "Age".