110,538
社区成员
发帖
与我相关
我的任务
分享
Class A
{
[CusAttribute("xx","pp")]
public string listName{get;set;}
[CusAttribute("xx","pp2")]
public list<string> listField{get;set}
}
typeof(A).GetProperties().Where(p => p.PropertyType.IsGenericType
&& p.PropertyType.GetInterface("IEnumerable", false) != null
&& typeof(string) == p.PropertyType.GetGenericArguments()[0])
.ToList().ForEach(p => Console.WriteLine(p.Name));
[Serializable, ComVisible(true)]
public sealed class String : IComparable, ICloneable, IConvertible, IComparable<string>, IEnumerable<char>, IEnumerable, IEquatable<string>
{
... ...
}
typeof(A).GetProperties().Where(p => p.PropertyType.GetInterface("IEnumerable", false) != null).ToList().ForEach(p => Console.WriteLine(p.Name));
事实上 string 也是可以forech的,所以也属于这个范围Test t = new Test();
Type type = t.GetType();
System.Reflection.PropertyInfo[] pis = type.GetProperties();
foreach (System.Reflection.PropertyInfo pi in pis)
{
if(pi.PropertyType.IsEnum)
//枚举属性
else
//不是枚举属性
}
public class Test
{
public string a
{
get;
set;
}
public EnumNum b
{
get;
set;
}
}
public enum EnumNum
{
one,
two
}