下载app免费领取会员
class Program
{
static void Main(string[] args)
{
//dynamic v = new ExpandoObject();
//v.Name = "123";
//v.Value = "456";
dynamic v = new TestClass();
v.Name = "Name";
v.Value = "Value";
Console.WriteLine(v.Name);
Console.ReadLine();
}
}
public class TestClass:DynamicObject
{
private Dictionary<string, object> _dynamicData = new Dictionary<string, object>();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = null;
if(_dynamicData.Keys.Contains(binder.Name))
{
result = _dynamicData[binder.Name];
return true;
}
return false;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if(_dynamicData.Keys.Contains(binder.Name))
{
_dynamicData[binder.Name] = value;
}
else
{
_dynamicData.Add(binder.Name, value);
}
return true;
}
}
本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。
上一篇:二次开发教程:WPF 使用INotifyDataErrorInfo小例子
下一篇:关于revit中平面窗族的创建