VS2015的GetIndexParameters()函数不好用,何解,高手帮忙
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()取不出值来呀,郁闷。。。
高手有什么其他办法么,分不够可以加。