字典上的 GetIndexParameters() 为空 属性
GetIndexParameters() empty on Dictionary property
我正在使用反射获取有关 class 的一些信息,我正在导出到 excel。它遍历属性以获取它们的值。
我希望它也能够处理索引类型,例如 List
s 和 Dictionary
s。但是,属性 上的 GetIndexParameters()
方法返回 none。我用错了吗?
在这里您可以看到 prop.Property
(即 PropertyInfo
)将值显示为 Dictionary<int, decimal>
,但 indexParams
的长度为 0。
循环逻辑(针对SO略作修改,部分伪代码)
foreach (var prop in ExportingPropertiesInOrder)
{
//detect if it needs to have indexing applied.
var indexParams = prop.Property.GetIndexParameters();
var isIndexed = indexParams.Any();
if (!isIndexed)
{
//get value for property for export
}else{
//loop through indeces, get each value
}
屏幕截图中显示的 属性 是 Dictionary<int, decimal> TierValues
它不是索引器,因此 属性 上的 GetIndexParameters()
方法返回空数组
Dictionary<int, decimal>
类型本身已编入索引 属性 Item
我正在使用反射获取有关 class 的一些信息,我正在导出到 excel。它遍历属性以获取它们的值。
我希望它也能够处理索引类型,例如 List
s 和 Dictionary
s。但是,属性 上的 GetIndexParameters()
方法返回 none。我用错了吗?
在这里您可以看到 prop.Property
(即 PropertyInfo
)将值显示为 Dictionary<int, decimal>
,但 indexParams
的长度为 0。
循环逻辑(针对SO略作修改,部分伪代码)
foreach (var prop in ExportingPropertiesInOrder)
{
//detect if it needs to have indexing applied.
var indexParams = prop.Property.GetIndexParameters();
var isIndexed = indexParams.Any();
if (!isIndexed)
{
//get value for property for export
}else{
//loop through indeces, get each value
}
屏幕截图中显示的 属性 是 Dictionary<int, decimal> TierValues
它不是索引器,因此 属性 上的 GetIndexParameters()
方法返回空数组
Dictionary<int, decimal>
类型本身已编入索引 属性 Item