我的一个函数出了点小问题。当我对递归部分进行注释时,我在DropDownList中得到了4个项目。但是,当我取消对递归部分的注释时,我得到错误消息“参数计数不匹配”。
我查看了一些函数,但到目前为止什么也没有找到。该函数接受第一个对象,它是一个格式化的JSON数据。然后,它应该给我类中每个属性的值。
编辑:我按照发布的示例(Parameter Count Mismatch exception when calling PropertyInfo.GetValue)做了,但现在我得到错误"System.Reflection.RuntimeParameterInfo‘无法转换为类型’System.Int32‘“有什么想法吗?我还编辑了代码:
protected void wystaw_liste(object obj)
{
if (obj == null) return;
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
object propValue = new object();
ParameterInfo[] index = property.GetIndexParameters();
if (index.Count() == 0)
{
propValue = property.GetValue(obj, null);
}
else
{
propValue = property.GetValue(obj, index);
}
var elems = propValue as IList;
if (elems != null)
{
foreach (var item in elems)
{
wystaw_liste(item);
}
}
else
{
if (property.PropertyType.Assembly != type.Assembly)
{
if (propValue != null)
{
parametry_list.Add(propValue.ToString());
}
}
}
}
}
你知道怎么解决这个问题吗?
https://stackoverflow.com/questions/56761661
复制相似问题