早就聽說過
有了dynamic
不知道
下面是使用DynamicDictionary與Dictionary的對照
public class DynamicDictionary : DynamicObject
{
Dictionary<string
public override bool TrySetMember(SetMemberBinder binder
{
_dictionary[binder
return true;
}
public override bool TryGetMember(GetMemberBinder binder
{
return _dictionary
}
}
[TestFixture]
public class TestDynamicDict
{
[Test]
public void Using_Dict()
{
var dict = new Dictionary<string
dict[
dict[
Console
}
[Test]
public void Using_Dynamic_Dict()
{
dynamic dict = new DynamicDictionary()
dict
dict
Console
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12259.html