ここDictionary<string,K>
で、K はリフレクションによって読み込まれる型です。K に名前を付けることはできません。
残念ながら、このメソッドをどのように使用すればよいかわかりませんTryGetValue
。私はいくつかの異なることを試しましたが、それらはすべて例外につながります。私は何をすればいいですか?
dynamic dict = GetDictThroughMagic();
dynamic d;
bool hasValue = dict.TryGetValue("name",out d);
bool hasValue = dict.TryGetValue("name",d);
私はより詳細に書くことができますif(dict.Contains("name")) d=dict["name"]
しかし、より簡潔な TryGetValue アプローチを記述できればと思います。
実際の例外を含めるように更新:
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The
best overloaded method match for 'System.Collections.Generic.Dictionary<string,K>
.TryGetValue(string, out K)' has some invalid arguments
at CallSite.Target(Closure , CallSite , Object , String , Object& )