如何使用反射确定一个属性是否实现了IList接口,如何确定元素量为空的集合的元素类型。如有个属性public List<int> Test{get{return new List<int>;}}
在使用反射的GetType().GetPropety()时如何确定Test实现了IList接口如果Test.Count==0,如何确定其元素类型(即结果应为typeof(int))
在使用反射的GetType().GetPropety()时如何确定Test实现了IList接口如果Test.Count==0,如何确定其元素类型(即结果应为typeof(int))
解决方案 »
- c# 编辑XML文件
- 如何删除dataset中的当前行或者列
- 求一个开源的出PDF帐票的工具,C#.NET用,大家有用过的麻烦提供一个,谢谢
- 一个窗口重载问题....
- 新手上路!请求高手帮忙。。。。。
- 请问类似[Designer(XXXXXX 的东西怎么用?
- 关于Remoting中客户端注册服务器端事件的问题
- 如何将当前日期转换为double类型?
- 取位查询??搞了很多天觉得有点难请教!
- 请教各位大哥,那里有关于用c#做web的资料,例如做留言版,论坛,登陆。。等等,请告知,本人不胜感激
- [散分200][分享]郁闷大发了,有关BindingSource和IList<自定义>类型的绑定问题
- C# 如何根据GUID获取COM中的接口
If (typeInterface==null)
return false;
else
return true;用类似的代码看看
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>(); } }
}
}