I know that now in C# 3.0 we can use dynamic keyword to add/remove properties in run time like the Object as general container's JavaScript concept, but i have a question.
Is it really Expand the object of the type i want ??
For Example: We have class:
class Person
{
public string Name { get; set; }
public int Age { get; set;}
}
I will create a new object from Person Class:
dynamic p = new ExpandoObject();
Now is this object really an object of class Person ? it dose not related to Person class anymore ??
Console.WriteLine(p.GetType()); // System.Dynamic.ExpandoObject
Now i will set values for properties and Expand object p with new property 'Foo':
p.Age = 25;
p.Foo = "foo";
I attached new property 'Foo' and set value for property 'Age' but i do that for an object of type System.Dynamic.ExpandoObject not of type Person so i have mismatch in this part, is i really expand the object from the type i needed, can i uses cast to refer to the object type like that:
Console.WriteLine(((Person)p).Name);
An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll