[英]Read Data From System.Collections.Generic.Dictionary`2[System.Object,System.Object]
I'm struggling to read data out of an IDictionary and would really appreciate some help. 我正在努力从IDictionary中读取数据,并希望得到一些帮助。 I've pulled out other data I need when it was just an object array, but I've got a KeyValuePair to deal with now.
当它只是一个对象数组时,我已经取出了我需要的其他数据,但是现在有一个KeyValuePair可以处理。 When I try and cast it as a KeyValuePair, I get an InvalidCastException so I did this to try and find the type:
当我尝试将其强制转换为KeyValuePair时,我收到了InvalidCastException,因此我这样做是为了尝试找到类型:
var test = plist["CFBundleIcons"];
MessageBox.Show(test.GetType().ToString());
Which returned System.Collections.Generic.Dictionary`2[System.Object,System.Object] . 哪个返回System.Collections.Generic.Dictionary`2 [System.Object,System.Object] 。 My first question is what does the 2 mean?
我的第一个问题是2是什么意思? I've used dictionaries in the past and have never seen this before.
我过去使用过字典,但从未见过。
If it helps understand my main problem further, I've attached a screenshot of the locals view below - I'm trying to read the icon names. 如果它有助于进一步了解我的主要问题,请在下面附上本地视图的屏幕截图-我正在尝试阅读图标名称。 Thanks in advance.
提前致谢。
This is how the CLR encodes generic type names. 这就是CLR编码通用类型名称的方式。
`2
indicates the number of type parameters in the type. `2
表示类型中类型参数的数量。
In C# terms, this is Dictionary<object, object>
. 用C#术语来说,这是
Dictionary<object, object>
。
It's just how .NET encodes a name of a generic type with two type parameters. 这就是.NET用两个类型参数编码通用类型名称的方式。
plist["CFBundleIcons"]
is a Dictionary<object, object>
. plist["CFBundleIcons"]
是Dictionary<object, object>
。 So instead of casting it to KeyValuePair
, you should cast it to the correct type. 因此,与其将其转换为
KeyValuePair
, KeyValuePair
将其转换为正确的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.