Type type =typeof(AgvResponseStatusParamVO);PropertyInfo propertyInfo = type.GetProperty(nameof(AgvResponseStatusParamVO.robotCode));Attribute attribute= propertyInfo.GetCustomAttribute(typeof(DescriptionAttribute),false);string name = attribute !=null?((DescriptionAttribute)attribute).Description :null;
获取枚举类型的值的Discription 特性
Type type =typeof(eLogLevel);string name=Enum.GetName(type, eLogLevel.info);FieldInfo fieldInfo= type.GetField(name);Attribute attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>(false);
name = attribute !=null?((DescriptionAttribute)attribute).Description :null;
获取类中所有字段的Discription 特性
Type type =typeof(AgvResponseStatusParamVO);PropertyInfo[] properties = type.GetProperties();foreach(PropertyInfo item in properties){DescriptionAttribute[] attributes=(DescriptionAttribute[])item.GetCustomAttributes(typeof(DescriptionAttribute),false);string desc = attributes?.Length >0? attributes[0].Description :null;}