我应该在以下函数中更改它以便编译和正常工作?
private void Test()
{
dynamic dyn;
dyn.Prop1 = 'A';
dyn.Prop2 = "asdfsdf";
dyn.Prop3 = 5;
foreach (PropertyInfo propertyInfo in dyn.GetType().GetProperties())
{
Console.WriteLine(propertyInfo.Name);
}
}
提前致谢!
答案 0 :(得分:4)
您可能正在寻找ExpandoObject
。
要查看有哪些属性(取自MSDN):
dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
employee.Age = 33;
foreach (var property in (IDictionary<String, Object>)employee)
{
Console.WriteLine(property.Key + ": " + property.Value);
}