本文整理汇总了C#中System.Reflection.PropertyInfo.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetCustomAttribute方法的具体用法?C# PropertyInfo.GetCustomAttribute怎么用?C# PropertyInfo.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputePropertyVisibility
private static bool ComputePropertyVisibility(PropertyInfo propertyInfo, bool bypassParam, VisibilityLevel visibilityLevel)
{
bool isVisible = false;
var hiddenAttribute = propertyInfo.GetCustomAttribute(typeof(HiddenWhenAttribute));
var visibilityByPassAttribute = propertyInfo.GetCustomAttribute(typeof(VisibilityByPassAttribute));
if (visibilityByPassAttribute == null && hiddenAttribute == null) // no attribute = keep in any case
{
isVisible = true;
}
else if (visibilityByPassAttribute != null && bypassParam) // bypass attribute + bypassParam = keep
{
isVisible = true;
}
else if (hiddenAttribute != null)
{
HiddenWhenAttribute hiddenLevels = hiddenAttribute as HiddenWhenAttribute;
if (hiddenLevels != null)
{
if (!hiddenLevels.Levels.Contains(visibilityLevel))
isVisible = true;
}
}
else
{
isVisible = false;
}
return isVisible;
}
示例2: TsProperty
/// <summary>
/// Initializes a new instance of the TsProperty class with the specific CLR property.
/// </summary>
/// <param name="memberInfo">The CLR property represented by this instance of the TsProperty.</param>
public TsProperty(PropertyInfo memberInfo)
{
this.MemberInfo = memberInfo;
this.Name = memberInfo.Name;
var propertyType = memberInfo.PropertyType;
if (propertyType.IsNullable()) {
propertyType = propertyType.GetNullableValueType();
}
this.GenericArguments = propertyType.IsGenericType ? propertyType.GetGenericArguments().Select(o => new TsType(o)).ToArray() : new TsType[0];
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);
// Only fields can be constants.
this.ConstantValue = null;
}
示例3: Column
public Column(PropertyInfo prop)
{
Setter = prop.ToSetter();
var rowNumberAttr = prop.GetCustomAttribute<RowNumberAttribute>();
IsRowNumber = rowNumberAttr != null;
var columnAttr = prop.GetCustomAttribute<ColumnAttribute>();
Name = columnAttr == null ? prop.Name : columnAttr.Name;
AccessName = prop.Name;
NotAllowedEmpty = prop.GetCustomAttribute<AllowedEmptyAttribute>() == null;
var indexedAttr = prop.GetCustomAttribute<IndexedColumnAttribute>();
if (indexedAttr != null)
{
IndexedNames = indexedAttr.Indexes.Select(x => Name + x).ToList();
}
if (IndexedNames == null) ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
else
{
var type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
ColumnType = type.GenericTypeArguments[0];
}
}
示例4: OptionPropertyValue
public OptionPropertyValue(PropertyInfo propertyInfo, object owner)
{
_propertyInfo = propertyInfo;
_owner = owner;
_displayName = _propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
_description = _propertyInfo.GetCustomAttribute<DescriptionAttribute>();
}
示例5: BooleanFieldMetadata
/// <summary>
/// Initializes a new instance of the <see cref="BooleanFieldMetadata"/> class.
/// </summary>
/// <param name="declaringProcess">
/// The declaring process.
/// </param>
/// <param name="editProperty">
/// The editable root property info.
/// </param>
/// <param name="infoProperty">
/// The info class property info.
/// </param>
public BooleanFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
: base(declaringProcess, editProperty, infoProperty)
{
var isSwitchToggleAttribute = editProperty.GetCustomAttribute<IsSwitchToggleAttribute>(false);
_isSwitchToggle = isSwitchToggleAttribute != null && true.Equals(isSwitchToggleAttribute.Value);
_undefinedLabelAttribute = editProperty.GetCustomAttribute<UndefinedLabelAttribute>(false);
_falseLabelAttribute = editProperty.GetCustomAttribute<FalseLabelAttribute>(false);
_trueLabelAttribute = editProperty.GetCustomAttribute<TrueLabelAttribute>(false);
_mainLabelAttribute = editProperty.GetCustomAttribute<MainLabelAttribute>(false);
}
示例6: PropertyProxy
public PropertyProxy(PropertyInfo pi, object target)
{
Name = pi.GetCustomAttribute<DisplayNameAttribute>(false)?.DisplayName ?? pi.Name;
Description = pi.GetCustomAttribute<DescriptionAttribute>(false)?.Description ?? "";
Order = pi.GetCustomAttribute<OrderAttribute>(false)?.Order ?? int.MaxValue;
Visible = pi.GetCustomAttribute<VisibleAttribute>(false)?.Visible ?? true;
Property = pi;
Target = target;
RegisterPropertyChanged();
}
示例7: PropertyMap
public PropertyMap(PropertyInfo propertyInfo)
{
this.PropertyInfo = propertyInfo;
this.Ignored = propertyInfo.GetCustomAttribute<NotMappedAttribute>() != null;
this.IsKey = propertyInfo.GetCustomAttribute<KeyAttribute>() != null;
var columnAttribute = propertyInfo.GetCustomAttribute<ColumnAttribute>();
this.ColumnName = columnAttribute?.Name ?? PropertyInfo.Name;
var databaseGeneratedAttribute = propertyInfo.GetCustomAttribute<DatabaseGeneratedAttribute>();
this.DatabaseGeneratedOption = databaseGeneratedAttribute?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
}
示例8: CreatePropertyObject
public static Property CreatePropertyObject(PropertyInfo propInfo, out Dictionary<string, Structure> structures)
{
structures = new Dictionary<string, Structure>();
Property result = new VSPlugin.Property();
string itemsType = "";
Structure structure = null;
// we need to verify if we have a structure in this property
StructureAttribute structureAttribute = propInfo.GetCustomAttribute<StructureAttribute>();
if (structureAttribute != null)
result.Type = structureAttribute.Type;
else
result.Type = Utility.HandleProperty(propInfo, out itemsType, out structure);
if (!string.IsNullOrEmpty(itemsType))
{
result.Items = new ArraySchema();
result.Items.Type = itemsType;
}
if (structure != null)
structures.Add(propInfo.PropertyType.Name, structure);
PropertyAttribute propAttrib = propInfo.GetCustomAttribute<PropertyAttribute>();
if (propAttrib == null)
return result;
result.Description = propAttrib.Description;
result.Required = propAttrib.Required;
result.Readonly = propAttrib.ReadOnly;
result.Final = propAttrib.Final;
result.Encrypted = propAttrib.Encrypted;
result.Unit = propAttrib.Unit;
result.Default = propAttrib.Default;
result.Format = propAttrib.Format;
result.Pattern = propAttrib.Pattern;
result.Title = propAttrib.Title;
result.Headline = propAttrib.Headline;
result.MinLength = propAttrib.MinLength;
result.MaxLength = propAttrib.MaxLength;
result.MinItems = propAttrib.MinItems;
result.MaxItems = propAttrib.MaxItems;
result.UniqueItems = propAttrib.UniqueItems;
result.EnumValues = propAttrib.Enum;
result.EnumTitles = propAttrib.EnumTitles;
result.Access = Access.GetAccess(propInfo);
return result;
}
示例9: GetPropertyName
/// <summary>Gets the name of the property for JSON serialization.</summary>
/// <param name="property">The property.</param>
/// <returns>The name.</returns>
public static string GetPropertyName(PropertyInfo property)
{
var jsonPropertyAttribute = property.GetCustomAttribute<JsonPropertyAttribute>();
if (jsonPropertyAttribute != null && !string.IsNullOrEmpty(jsonPropertyAttribute.PropertyName))
return jsonPropertyAttribute.PropertyName;
if (property.DeclaringType.GetTypeInfo().GetCustomAttribute<DataContractAttribute>() != null)
{
var dataMemberAttribute = property.GetCustomAttribute<DataMemberAttribute>();
if (dataMemberAttribute != null && !string.IsNullOrEmpty(dataMemberAttribute.Name))
return dataMemberAttribute.Name;
}
return property.Name;
}
示例10: FromPropertyInfo
private SchemaInfo FromPropertyInfo(PropertyInfo pi)
{
if (!this.IsMapped(pi))
return null;
Type propertyType = pi.PropertyType;
bool nullableTypeDetected = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == CachedTypes.PureNullableType;
SchemaInfo schema = new SchemaInfo(pi.Name, nullableTypeDetected ? propertyType.GetGenericArguments()[0] : propertyType);
//NotMapped gibi bir standart
KeyAttribute keyAtt = pi.GetCustomAttribute<KeyAttribute>();
if (null != keyAtt)
schema.IsKey = true;
if (nullableTypeDetected)
schema.IsNullable = true;
else
{
if (propertyType.IsClass)
schema.IsNullable = true;
else if (propertyType.IsValueType)
schema.IsNullable = false;
}
bool hasSetMethod = pi.GetSetMethod() != null;
if (!hasSetMethod)
schema.ReadOnly = true;
this.SetExtendedSchema(schema, pi);
return schema;
}
示例11: NumericFieldMetadata
/// <summary>
/// Initializes a new instance of the <see cref="NumericFieldMetadata"/> class.
/// </summary>
/// <param name="declaringProcess">
/// The declaring process.
/// </param>
/// <param name="editProperty">
/// The editable root property info.
/// </param>
/// <param name="infoProperty">
/// The info class property info.
/// </param>
public NumericFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
: base(declaringProcess, editProperty, infoProperty)
{
var fieldTypeAttribute = editProperty.GetCustomAttribute<FieldTypeAttribute>(false);
if (fieldTypeAttribute == null)
throw new ArgumentException("FieldType attribute not found.");
_columnType = fieldTypeAttribute.ColumnType;
var numericAttribute = editProperty.GetCustomAttribute<NumericAttribute>(false);
if (numericAttribute != null)
{
_numericType = numericAttribute.NumericType;
_decimalDigits = numericAttribute.NumberOfDigits;
}
}
示例12: TwoRadioOptionsControl
/// <summary>
/// Requires that the bound property has two options in order to bind properly.
/// </summary>
public TwoRadioOptionsControl(PropertyInfo property)
{
InitializeComponent();
// Knowing the property info allows us to dynamically generarte the available options based on the class attributes
// and bind the results to a specified type
BoundProperty = property;
var parameterAttribute = BoundProperty.GetCustomAttribute<ItemConditionParameterAttribute>();
if (parameterAttribute == null)
throw new Exception(
"Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");
if (parameterAttribute.Options == null || parameterAttribute.Options.Count() != 2)
throw new Exception(
"Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");
BoundOptions = parameterAttribute.Options;
ValueLabel.Text = string.IsNullOrEmpty(parameterAttribute.Name) ? property.Name : parameterAttribute.Name;
OptionOneRadioButton.Text = parameterAttribute.Options[0].Name;
OptionTwoRadioButton.Text = parameterAttribute.Options[1].Name;
}
示例13: Build
public static TableFieldInfo Build(string tableName, PropertyInfo pi, IFieldHandlerFactory fieldHandlerFactory)
{
var fieldHandler = fieldHandlerFactory.CreateFromType(pi.PropertyType, FieldHandlerOptions.None);
if (fieldHandler == null) throw new BTDBException(string.Format("FieldHandlerFactory did not build property {0} of type {2} in {1}", pi.Name, tableName, pi.PropertyType.FullName));
var a = pi.GetCustomAttribute<PersistedNameAttribute>();
return new TableFieldInfo(a != null ? a.Name : pi.Name, fieldHandler);
}
示例14: GetLocalizationInfo
private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
{
var attr = prop.GetCustomAttribute<LocalizeAttribute>();
if(attr == null)
{
return null;
}
var info = new LocalizationInfo
{
ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
};
if(info.ResourceType != null)
{
info.ResourceType = attr.ResourceType;
}
else
{
var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
if(parent == null || parent.ResourceType == null)
{
throw new ArgumentException(String.Format(
"The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
prop.Name, prop.DeclaringType.Name));
}
info.ResourceType = parent.ResourceType;
}
return info;
}
示例15: GetFieldType
private static string GetFieldType(PropertyInfo property)
{
var dataTypeAttrib = property.GetCustomAttribute<DataTypeAttribute>();
if (dataTypeAttrib == null)
return null;
switch (dataTypeAttrib.DataType)
{
case DataType.Date:
return "date";
case DataType.DateTime:
return "datetime";
case DataType.EmailAddress:
return "email";
case DataType.ImageUrl:
return "image";
case DataType.Password:
return "password";
case DataType.Time:
return "time";
case DataType.Upload:
return "file";
default:
return typeof(HttpPostedFileBase).IsAssignableFrom(property.PropertyType) ? "file" : "text";
}
}