当前位置: 首页>>代码示例>>C#>>正文


C# PropertyInfo.GetAttribute方法代码示例

本文整理汇总了C#中System.Reflection.PropertyInfo.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetAttribute方法的具体用法?C# PropertyInfo.GetAttribute怎么用?C# PropertyInfo.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.PropertyInfo的用法示例。


在下文中一共展示了PropertyInfo.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetValueFromXml

        protected override object GetValueFromXml(XElement root, XName name, PropertyInfo prop)
        {
            var isAttribute = false;

            // Check for the DeserializeAs attribute on the property
            var options = prop.GetAttribute<DeserializeAsAttribute>();

            if (options != null)
            {
                name = options.Name ?? name;
                isAttribute = options.Attribute;
            }

            if (isAttribute)
            {
                var attributeVal = GetAttributeByName(root, name);

                if (attributeVal != null)
                {
                    return attributeVal.Value;
                }
            }

            return base.GetValueFromXml(root, name, prop);
        }
开发者ID:mgulubov,项目名称:RestSharpHighQualityCodeTeamProject,代码行数:25,代码来源:XmlAttributeDeserializer.cs

示例2: GetField

        private static Field GetField(PropertyInfo info, Type entityType)
        {
            if (!info.GetCustomAttributes(true).Any())
            {
                return new Field(info, entityType)
                           {
                               FieldName = info.Name,
                               FieldType = info.PropertyType,
                               IsKey = false,
                               IsIdentity = false
                           };
            }

            var dbField = info.GetAttribute<DbFieldAttribute>();
            if (dbField != null)
            {
                return new Field(info, entityType)
                           {
                               FieldName = GetFieldName(dbField, info),
                               FieldType = info.PropertyType,
                               IsKey = false,
                               IsIdentity = false
                           };
            }

            return new Field(info, entityType)
                       {
                           FieldName = GetKeyFieldName(info),
                           FieldType = info.PropertyType,
                           IsKey = IsKeyField(info),
                           IsIdentity = IsIdentityField(info)
                       };
        }
开发者ID:stalinvr007,项目名称:VoDB,代码行数:33,代码来源:FieldMapper.cs

示例3: LabelForPropertyConvention

		public override string LabelForPropertyConvention(PropertyInfo propertyInfo)
		{
			if (propertyInfo.AttributeExists<LabelAttribute>())
				return propertyInfo.GetAttribute<LabelAttribute>().Label;

			return base.LabelForPropertyConvention(propertyInfo);
		}
开发者ID:sthapa123,项目名称:codecampserver,代码行数:7,代码来源:InputBuilderPropertyConvention.cs

示例4: PropertyMapper

        /// <summary>
        /// 指定属性元数据,初始化一个 <see cref="PropertyMapper"/> 类的新实例。
        /// </summary>
        /// <param name="typeMapper">类型的映射器。</param>
        /// <param name="property">成员的属性元数据。</param>
        public PropertyMapper(TypeMapper typeMapper, PropertyInfo property)
            : base(property)
        {
            if(typeMapper == null) throw new ArgumentNullException(nameof(typeMapper));
            this.TypeMapper = typeMapper;
            this.IsIgnore = property.GetAttribute<IgnoreAttribute>() != null;
            this._LazyTypeDefaultValue = new Lazy<object>(property.PropertyType.GetDefaultValue);

            var aliasAttr = property.GetAttribute<IAliasAttribute>();
            this.Name = aliasAttr != null && aliasAttr.Name != null
                ? aliasAttr.Name
                : property.Name;

            var keyAttr = property.GetAttribute<IKeyAttribute>();
            this.IsKey = keyAttr != null && keyAttr.IsKey;
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:21,代码来源:PropertyMapper.cs

示例5: Descriptor

 /// <summary>Creates a new <see cref="Descriptor"/> instance from a given property.</summary>
 /// <param name="property">The property from which the descriptor will be created.</param>
 public Descriptor(PropertyInfo property) {
    var attr = property.GetAttribute<DescriptorAttribute>();
    if (attr != null) {
       ParseXml(attr.Markup);
    }
    Subject = property;
 }
开发者ID:borkaborka,项目名称:gmit,代码行数:9,代码来源:Descriptor.cs

示例6: CanHandle

 public override bool CanHandle(PropertyInfo propertyInfo)
 {
     if (propertyInfo.AttributeExists<DataTypeAttribute>())
     {
         return propertyInfo.GetAttribute<DataTypeAttribute>().DataType == DataType.EmailAddress;
     }
     return false;
 }
开发者ID:snahider,项目名称:Presentations,代码行数:8,代码来源:EmailPropertyConvention.cs

示例7: AssingDefaultValue

 public void AssingDefaultValue(PropertyInfo prop)
 {
     var attrib = prop.GetAttribute<SerializePropertyAttribute>();
     if (attrib.CreateNewAsDefaultValue)
         prop.SetValue(this, Activator.CreateInstance(prop.PropertyType), null);
     else if (attrib.DefaultValue != null)
         prop.SetValue(this, attrib.DefaultValue, null);
 }
开发者ID:kkalinowski,项目名称:lib12,代码行数:8,代码来源:SerializableViewModel.cs

示例8: PropertyMapper

        /// <summary>
        /// 指定属性元数据,初始化一个 <see cref="PropertyMapper"/> 类的新实例。
        /// </summary>
        /// <param name="typeMapper">类型的映射器。</param>
        /// <param name="property">成员的属性元数据。</param>
        public PropertyMapper(TypeMapper typeMapper, PropertyInfo property)
            : base(property)
        {
            if(typeMapper == null) throw new ArgumentNullException(nameof(typeMapper));
            this.TypeMapper = typeMapper;
            this.IsIgnore = property.GetAttribute<IgnoreAttribute>() != null;
            this._LazyTypeDefaultValue = new Lazy<object>(property.PropertyType.GetDefaultValue);

            var aliasAttr = property.GetAttribute<IAliasAttribute>();
            this.Name = aliasAttr != null && aliasAttr.Name != null
                ? aliasAttr.Name
                : property.Name;

            var keyAttr = property.GetAttribute<IKeyAttribute>();
            this.IsKey = (keyAttr != null && keyAttr.IsKey) || string.Equals(property.Name, DbExtensions.DefaultKeyName, StringComparison.CurrentCultureIgnoreCase);

            this.Validators = property.GetAttributes<IPropertyValidator>().ToArray();
        }
开发者ID:supuy-ruby,项目名称:Aoite,代码行数:23,代码来源:PropertyMapper.cs

示例9: CopyFromModel

 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(ss => ss.Name == ckf);
     var ck = ckpi.GetValue(model, null) as bool?;
     var m = modelProps.FirstOrDefault(mm => mm.Name == vm.Name);
     Number = ((string)m.GetValue(model, null)).FmtFone();
     ReceiveText = ck ?? false;
 }
开发者ID:stevesloka,项目名称:bvcms,代码行数:9,代码来源:BasicPersonInfo.cs

示例10: GetDefaultValue

        private static object GetDefaultValue(PropertyInfo member)
        {
            object defaultValue = null;
            var defaultAttribute = member.GetAttribute<DefaultAttribute>();
            if (defaultAttribute != null)
            {
                defaultValue = defaultAttribute.Default();
            }

            if (defaultValue == null)
            {
                var attribute = member.GetAttribute<DefaultValueAttribute>();
                if (attribute != null)
                {
                    defaultValue = attribute.Value;
                }
            }

            return defaultValue;
        }
开发者ID:miensol,项目名称:SimpleConfigSections,代码行数:20,代码来源:ConfigurationPropertyFactory.cs

示例11: GetInitialValue

        public object GetInitialValue(PropertyInfo accessor)
        {
            var defaultAttrib = accessor.GetAttribute<DefaultValueAttribute>();

            if (defaultAttrib != null)
            {
                return defaultAttrib.Value;
            }

            return accessor.PropertyType.GetDefaultValue();
        }
开发者ID:attila3453,项目名称:alsing,代码行数:11,代码来源:MetaInfoDeclaration.cs

示例12: MustBeHidden

        protected static bool MustBeHidden(PropertyInfo propertyInfo)
        {
            var hiddenInputAttribute = propertyInfo.GetAttribute<HiddenInputAttribute>();
            return (hiddenInputAttribute != null && !hiddenInputAttribute.DisplayValue);
            //return true;

            //var displayAttribute = propertyInfo.GetAttribute<DisplayAttribute>();
            //if (displayAttribute == null)
            //    return false;

            //return false;
        }
开发者ID:dwdkls,项目名称:pizzamvc,代码行数:12,代码来源:ModelRendererBase.cs

示例13: createParameter

        public static Parameter createParameter(PropertyInfo propertyInfo, IRouteDefinition route)
        {
            var parameter = new Parameter
                                {
                                    name = propertyInfo.Name,
                                    dataType = propertyInfo.PropertyType.Name,
                                    paramType = "post",
                                    allowMultiple = false,
                                    required = propertyInfo.HasAttribute<RequiredAttribute>(),
                                    description = propertyInfo.GetAttribute<DescriptionAttribute>(a => a.Description),
                                    defaultValue = propertyInfo.GetAttribute<DefaultValueAttribute>(a => a.Value.ToString()),
                                    allowableValues = getAllowableValues(propertyInfo)
                                };

            if (route.Input.RouteParameters.Any(r => r.Name == propertyInfo.Name))
                parameter.paramType = "path";

            if (route.Input.QueryParameters.Any(r => r.Name == propertyInfo.Name))
                parameter.paramType = "query";

            return parameter;
        }
开发者ID:styson,项目名称:fubumvc-swagger,代码行数:22,代码来源:SwaggerMapper.cs

示例14: GetTextBlobChild

        public static void GetTextBlobChild(object element, PropertyInfo relationshipProperty)
        {
            var type = element.GetType();
            var relationshipType = relationshipProperty.PropertyType;

            Debug.Assert(relationshipType != typeof(string), "TextBlob property is already a string");

            var textblobAttribute = relationshipProperty.GetAttribute<TextBlobAttribute>();
            var textProperty = type.GetProperty(textblobAttribute.TextProperty, typeof (string));
            Debug.Assert(textProperty != null, "Text property for TextBlob relationship not found");

            var textValue = (string)textProperty.GetValue(element, null);
            var value = textValue != null ? GetTextSerializer().Deserialize(textValue, relationshipType) : null;

            relationshipProperty.SetValue(element, value, null);
        }
开发者ID:jsteranko,项目名称:nfl.NET,代码行数:16,代码来源:TextBlobOperations.cs

示例15: UpdateTextBlobProperty

        public static void UpdateTextBlobProperty(object element, PropertyInfo relationshipProperty)
        {
            var type = element.GetType();
            var relationshipType = relationshipProperty.PropertyType;

            Debug.Assert(relationshipType != typeof(string), "TextBlob property is already a string");

            var textblobAttribute = relationshipProperty.GetAttribute<TextBlobAttribute>();
            var textProperty = type.GetRuntimeProperty(textblobAttribute.TextProperty);
            Debug.Assert(textProperty != null && textProperty.PropertyType == typeof(string), "Text property for TextBlob relationship not found");

            var value = relationshipProperty.GetValue(element, null);
            var textValue = value != null ? GetTextSerializer().Serialize(value) : null;

            textProperty.SetValue(element, textValue, null);
        }
开发者ID:dsb92,项目名称:patientcare,代码行数:16,代码来源:TextBlobOperations.cs


注:本文中的System.Reflection.PropertyInfo.GetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。