[Serializable]
    public class Product : BaseObject
    {
        [XmlElement("binds")]
        public string Binds { get; set; }        [XmlElement("binds_str")]
        public string BindsStr { get; set; }        [XmlElement("cat_name")]
        public string CatName { get; set; }        [XmlElement("cid")]
        public long Cid { get; set; }        [XmlElement("created")]
        public string Created { get; set; }        [XmlElement("desc")]
        public string Desc { get; set; }        [XmlElement("modified")]
        public string Modified { get; set; }        [XmlElement("name")]
        public string Name { get; set; }        [XmlElement("outer_id")]
        public string OuterId { get; set; }        [XmlElement("pic_url")]
        public string PicUrl { get; set; }        [XmlElement("price")]
        public string Price { get; set; }        [XmlElement("product_id")]
        public long ProductId { get; set; }        [XmlArray("product_imgs")]
        [XmlArrayItem("product_img")]
        public List<ProductImg> ProductImgs { get; set; }        [XmlArray("product_prop_imgs")]
        [XmlArrayItem("product_prop_img")]
        public List<ProductPropImg> ProductPropImgs { get; set; }        [XmlElement("props")]
        public string Props { get; set; }        [XmlElement("props_str")]
        public string PropsStr { get; set; }        [XmlElement("sale_props")]
        public string SaleProps { get; set; }        [XmlElement("sale_props_str")]
        public string SalePropsStr { get; set; }        [XmlElement("status")]
        public long Status { get; set; }        [XmlElement("tsc")]
        public string Tsc { get; set; }        [XmlElement("vertical_et")]
        public long VerticalMarket { get; set; }
    }就是我想等到这些字段binds,binds_str,cat_name,cid  描述的一些字符串 全部的

解决方案 »

  1.   

    partial class Program
    {
        static void Main()
        {
            PropertyInfo[] peroperties = typeof(A).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo property in peroperties)
            {
                object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (objs.Length > 0)
                {
                  Console.WriteLine("{0}: {1}", property.Name, ((DescriptionAttribute)objs[0]).Description);
                }
            }
            Console.ReadKey();
        }
    }class A
    {
        [Description("X")]
        public string X
        {
            get { return null; }
        }
        [Description("Y")]
        public string Y
        {
            get { return null; }
        }
    }
      

  2.   

    反射,一般要获取元数据都得通过反射partial class Program
    {
      static void Main()
      {
      PropertyInfo[] peroperties = typeof(A).GetProperties(BindingFlags.Public | BindingFlags.Instance);
      foreach (PropertyInfo property in peroperties)
      {
      object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
      if (objs.Length > 0)
      {
      Console.WriteLine("{0}: {1}", property.Name, ((DescriptionAttribute)objs[0]).Description);
      }
      }
      Console.ReadKey();
      }
    }class A
    {
      [Description("X")]
      public string X
      {
      get { return null; }
      }
      [Description("Y")]
      public string Y
      {
      get { return null; }
      }
    }