VS2015的GetIndexParameters()函数不好用,何解,高手帮忙

yzlyboy 2016-08-23 08:38:02
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Text;

namespace soft.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = new B();
B bb = new B();
a.P = "aaa";
a.Q = "uuuu";
b.M = "1233-333";
b.N = "223333-000";
BCollection li = new BCollection();
bb.M = "9999";
bb.N = "88888";
a.O = b;
li.Add(b);
li.Add(bb);
a.OO = li.ToList();

B newB = new B();
newB.M = "new111";
newB.N = "new222";
BCollection lii = new BCollection();
lii.Add(newB);

B newC = new B();
newC.M = "new333";
newC.N = "new444";
BCollection liii = new BCollection();
liii.Add(newC);

foreach (PropertyInfo item in a.GetType().GetProperties())
{
if (item.PropertyType.IsGenericType)
{
////@@GetIndexParameters()<--取不出值,郁闷 @@VS2010能取值,VS2015取不出值
var paras = item.GetIndexParameters();
object tempItem = item.GetValue(a, null);

System.Console.WriteLine(tempItem.ToString());

item.SetValue(a, lii, new object[] { });

tempItem = item.GetValue(a, null);

System.Console.WriteLine(tempItem.ToString());

item.SetValue(a, liii, new object[] { 0 });

tempItem = item.GetValue(a, null);

System.Console.WriteLine(tempItem.ToString());
}
}

//System.Console.WriteLine(b.N);

}
}
class BCollection : KeyedCollection<string, B>
{
protected override string GetKeyForItem(B xpath)
{
return xpath.M;
}
}

[Serializable]
public class A
{
public string P
{ get; set; }
public string Q
{ get; set; }
public B O
{ get; set; }

public IList<B> OO
{ get; set; }
}

[Serializable]
public class B
{
public string M
{ get; set; }

public string N
{ get; set; }
}
}
---------------------------------------------
@@处的GetIndexParameters()取不出值来呀,郁闷。。。
高手有什么其他办法么,分不够可以加。
...全文
155 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2016-08-24
  • 打赏
  • 举报
回复
你没有定义索引器。是不是你想调用 GetGenericArguments
Poopaye 2016-08-23
  • 打赏
  • 举报
回复
扯淡吧,就算2010拿出来的也是0个 这个函数是为了拿索引器的参数的 A类里哪有索引器?

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧