Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the TsProperty class with the specific CLR field.
        /// </summary>
        /// <param name="memberInfo">The CLR field represented by this instance of the TsProperty.</param>
        public TsProperty(System.Reflection.FieldInfo memberInfo)
        {
            this.MemberInfo = memberInfo;
            this.Name       = memberInfo.Name;

            if (memberInfo.ReflectedType.IsGenericType)
            {
                var definitionType         = memberInfo.ReflectedType.GetGenericTypeDefinition();
                var definitionTypeProperty = definitionType.GetProperty(memberInfo.Name);
                if (definitionTypeProperty.PropertyType.IsGenericParameter)
                {
                    this.PropertyType = TsType.Any;
                }
                else
                {
                    this.PropertyType = memberInfo.FieldType.IsEnum ? new TsEnum(memberInfo.FieldType) : new TsType(memberInfo.FieldType);
                }
            }
            else
            {
                var propertyType = memberInfo.FieldType;
                if (propertyType.IsNullable())
                {
                    propertyType = propertyType.GetNullableValueType();
                }

                this.PropertyType = propertyType.IsEnum ? new TsEnum(propertyType) : new TsType(propertyType);
            }

            var attribute = memberInfo.GetCustomAttribute <TsPropertyAttribute>(false);

            if (attribute != null)
            {
                if (!string.IsNullOrEmpty(attribute.Name))
                {
                    this.Name = attribute.Name;
                }

                this.IsOptional = attribute.IsOptional;
            }

            this.IsIgnored = (memberInfo.GetCustomAttribute <TsIgnoreAttribute>(false) != null);

            if (memberInfo.IsLiteral && !memberInfo.IsInitOnly)
            {
                // it's a constant
                this.ConstantValue = memberInfo.GetValue(null);
            }
            else
            {
                // not a constant
                this.ConstantValue = null;
            }
        }
Exemplo n.º 2
0
        private static void SetBitInfoFromFieldInfo(BitUserInterfaceData bitInfo, System.Reflection.FieldInfo bitFieldInfo)
        {
            var attr_display_name = bitFieldInfo.GetCustomAttribute <System.ComponentModel.DataAnnotations.DisplayAttribute>();

            if (attr_display_name != null)
            {
                bitInfo.DisplayName = attr_display_name.Name;
            }
            else
            {
                bitInfo.DisplayName = bitFieldInfo.Name;
            }

            var attr_description = bitFieldInfo.GetCustomAttribute <System.ComponentModel.DescriptionAttribute>();

            if (attr_description != null)
            {
                bitInfo.Description = attr_description.Description;
            }
            else
            {
                if (attr_display_name != null)
                {
                    bitInfo.Description = attr_display_name.Description;
                }

                if (bitInfo.Description == null)
                {
                    bitInfo.Description = string.Empty;
                }
            }

            var attr_browsable = bitFieldInfo.GetCustomAttribute <System.ComponentModel.BrowsableAttribute>();

            if (attr_browsable != null)
            {
                bitInfo.Visible = attr_browsable.Browsable;
            }
            else
            {
                bitInfo.Visible = true;
            }
        }