解决方案 »

  1.   

    反射得到PropertyInfo,然后调用Attribute.GetCustomAttributes
      

  2.   


    用反射得到PropertyInfo,和我用TypeDescriptor.GetProperties(this, true)得到PropertyDescriptorCollection,由什么区别呢? 是同样的实现机制,还是说不同的实现机制,得到的东西也可能不同?
      

  3.   

    我把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);
                        }
                    }
                }
            }