using System.Dynamic;
namespace Test
{
public class Test
{
public static void Main(string[] args)
{
new Test().CustomTest();
}
private void CustomTest()
{
dynamic person = new ExpandoObject(); //ExpandoObject 为密封类
Func<int, string> doSomething = ID => ID.ToString(); //定义委托方法
person.GetID = doSomething; //运行时动态添加方法
person.Name = "吴某某"; //运行时动态添加了属性Name
Console.WriteLine(person.Name + " " + person.GetID(50)); // person.GetID(50) 方法调用
}
}
}