如何得到一个Attribute的名字? http://msdn.microsoft.com/zh-cn/library/system.attribute(VS.80).aspx 看看介绍 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 反射得到PropertyInfo,然后调用Attribute.GetCustomAttributes 用反射得到PropertyInfo,和我用TypeDescriptor.GetProperties(this, true)得到PropertyDescriptorCollection,由什么区别呢? 是同样的实现机制,还是说不同的实现机制,得到的东西也可能不同? 我把LoopProp函数改成了下面这样,就可以达到期望了: public void LoopProp() { var props = TypeDescriptor.GetProperties(this, true); foreach (PropertyDescriptor prop in props) { foreach (Attribute a in prop.Attributes) { if (a.GetType() == typeof (CategoryAttribute)) { if(((CategoryAttribute)(a)).Category.Equals("YourString")) Console.WriteLine(prop.Name); } } } } 杨辉三角程序 关于c# webservice 的一个超难问题,非c#和java全会的高手不能解决啊! 关于字符拆分的问题 新手:获取cookie的值,请大家看看为什么获取不到 ctrl is IValidator 如题 经常用的代码如何共享? 请教excel的com组件导出excel图表的问题 我急需sql server安装版的压缩包 多人开发流程怎么控制 谁能解开这个迷团?? 请c#大牛帮助解决一下new的用法 DevExpress的TreeList如何显示底部滚动条
用反射得到PropertyInfo,和我用TypeDescriptor.GetProperties(this, true)得到PropertyDescriptorCollection,由什么区别呢? 是同样的实现机制,还是说不同的实现机制,得到的东西也可能不同?
{
var props = TypeDescriptor.GetProperties(this, true);
foreach (PropertyDescriptor prop in props)
{
foreach (Attribute a in prop.Attributes)
{
if (a.GetType() == typeof (CategoryAttribute))
{
if(((CategoryAttribute)(a)).Category.Equals("YourString"))
Console.WriteLine(prop.Name);
}
}
}
}