本文整理汇总了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);
}
示例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)
};
}
示例3: LabelForPropertyConvention
public override string LabelForPropertyConvention(PropertyInfo propertyInfo)
{
if (propertyInfo.AttributeExists<LabelAttribute>())
return propertyInfo.GetAttribute<LabelAttribute>().Label;
return base.LabelForPropertyConvention(propertyInfo);
}
示例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;
}
示例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;
}
示例6: CanHandle
public override bool CanHandle(PropertyInfo propertyInfo)
{
if (propertyInfo.AttributeExists<DataTypeAttribute>())
{
return propertyInfo.GetAttribute<DataTypeAttribute>().DataType == DataType.EmailAddress;
}
return false;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例11: GetInitialValue
public object GetInitialValue(PropertyInfo accessor)
{
var defaultAttrib = accessor.GetAttribute<DefaultValueAttribute>();
if (defaultAttrib != null)
{
return defaultAttrib.Value;
}
return accessor.PropertyType.GetDefaultValue();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}