首页 > 其他 > 详细

Attribute类的使用

时间:2019-06-30 09:32:19      阅读:108      评论:0      收藏:0      [点我收藏+]

为每个变量设置设置属性 "Description"

public class PatternOption
    {
        /// <summary>
        /// 方向图步长
        /// </summary>
        [Description("PT_SitaStepDeg")]
        public double StepDeg { get; set; }//
        /// <summary>
        /// 垂直面的切角(phi角)
        /// </summary>
        [Description("PT_VeritalCutPlaneDeg")]
        public double VeritalCutPlaneDeg { get; set; }
        /// <summary>
        /// 垂直面的切角(sita角)
        /// </summary>
        [Description("PT_HorizontalCutPlaneDeg")]
        public double HorizontalCutPlaneDeg { get; set; }
        /// <summary>
        /// 主瓣搜索起点
        /// </summary>
        [Description("PT_MBStartDeg")]
        public double MainbeamSearchStartDeg { get; set; }//
        /// <summary>
        /// 主瓣搜索终点
        /// </summary>
        [Description("PT_MBStopDeg")]
        public double MainbeamSearchStopDeg { get; set; }//   

        /// <summary>
        /// 上旁瓣搜索起点,相对于主瓣方向,deg
        /// </summary>
        [Description("PT_UBOffsDeg")]
        public double UBStartOffsetFromMainBeamDeg { get; set; }
        /// <summary>
        /// 上旁瓣搜索终点偏移量,相对于主瓣方向,def
        /// </summary>
        [Description("PT_SitaStepDeg")]
        public double UBEndOffsetFromMainBeamDeg { get; set; }//

        [Description("PT_UBOffsDeg")]
        public bool UBCorrectToEdge { get; set; }
        
       
       
    }

通过反射读取 Description

 

 #region 读取属性描述的例程,
            PatternOption patternOption = new PatternOption();
            Type type = patternOption.GetType();
            FieldInfo[] fieldInfos = type.GetFields();
            foreach (FieldInfo item in fieldInfos)
            {
                DescriptionAttribute[] attributes = (DescriptionAttribute[])item.GetCustomAttributes(typeof(DescriptionAttribute), false);
            } 
            #endregion

 

Attribute类的使用

原文:https://www.cnblogs.com/ccjungle/p/11108640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!