我有以下 expando 对象
dynamic person = new ExpandoObject();
person.FirstName = " FirstName ";
person.SecondName = " FirstName ";
person.FullName = person.FirstName + person.SecondName;
person.BirthDate = new DateTime(1990, 1, 1);
person.CalcAge = (Func<int>)
(() => DateTime.Now.Year - person.BirthDate.Year);
我定义CalcAge
了计算年龄的方法..我想添加具有如下参数的重载方法
person.CalcAge = (Func<DateTime, int>)
((DateTime date) => date.Year - person.BirthDate.Year);
我该如何实现它ExpandoObject
,我可以在其中执行以下操作?
int age1 = person.CalcAge();
MessageBox.Show(age1.ToString());
int age2 = person.CalcAge2(new DateTime(1980, 1, 1));
MessageBox.Show(age2.ToString());