您的位置:首页 > 其它

如何使用反射确定一个属性是否实现了IList接口,如何确定元素量为空的集合的元素类型。

2009-05-09 19:52 841 查看
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (PropertyInfo pi in typeof(Program).GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (Array.IndexOf(pi.PropertyType.GetInterfaces(), typeof(IList)) > -1)//查找实现了Ilist接口的属性
Console.WriteLine(pi.Name);
if (pi.PropertyType.IsGenericType)//如果该属性是泛型
{
foreach (Type t in pi.PropertyType.GetGenericArguments())//遍历输出属性的每个泛型参数类型
Console.WriteLine(t.FullName);
}
}
}

public List<int> Test { get { return new List<int>(); } }
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐