通过foreach提取JsonData来提取IDictionary
枚举,而不是IList
一个。
foreach (var jsonEntry in jsonData)
这导致我的代码抛出错误。
InvalidOperationException: Instance of JsonData is not a dictionary
LitJson.JsonData.EnsureDictionary ()
LitJson.JsonData.System.Collections.Specialized.IOrderedDictionary.GetEnumerator ()
LitJson.JsonData.System.Collections.IDictionary.GetEnumerator ()
将对象转换为IList
会导致Resharper发出警告“类型转换是多余的。”
foreach (var jsonEntry in jsonData as IList)
为什么Resharper认为演员是多余的?
答案 0 :(得分:1)
为什么Resharper认为演员是多余的?
如果你这么想:
IList是ICollection,IDictionary也是ICollection,因为它们都实现了'ICollection',Resharper的警告应该变得清晰。