本文整理汇总了C#中System.Reflection.MemberInfo.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.GetCustomAttribute方法的具体用法?C# MemberInfo.GetCustomAttribute怎么用?C# MemberInfo.GetCustomAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.GetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializableMember
/// <summary>
/// Initializes a new instance of the SerializableMember class.
/// </summary>
/// <param name="member">The member to serialize.</param>
private SerializableMember(MemberInfo member)
{
Debug.Assert(member != null, "member cannot be null!");
Debug.Assert(!member.Has<IgnoreDataMemberAttribute>(), "member should be ignored!");
this.Name = member.Name; // May be overwritten by DataMember below
this.MemberName = member.Name;
DataMemberAttribute dataMemberAttribute = member.GetCustomAttribute<DataMemberAttribute>(true);
if (dataMemberAttribute != null)
{
if (!string.IsNullOrWhiteSpace(dataMemberAttribute.Name))
{
this.Name = dataMemberAttribute.Name;
}
this.IsRequired = dataMemberAttribute.IsRequired;
this.Order = dataMemberAttribute.Order;
}
DataMemberJsonConverterAttribute converter = member.GetCustomAttribute<DataMemberJsonConverterAttribute>(true);
if (converter != null && converter.ConverterType != null)
{
this.Converter = SerializableType.GetConverter(converter.ConverterType);
}
}
示例2: MemberData
public MemberData(Type type, MemberInfo memberInfo)
{
Type = type;
ServiceKey = memberInfo.GetCustomAttribute<ServiceKeyAttribute>()?.Key;
InjectableAttribute = memberInfo.GetCustomAttribute<InjectableAttribute>();
}
示例3: PropertyOrField
protected PropertyOrField(MemberInfo memberInfo)
{
MemberInfo = memberInfo;
Base64Encoded = memberInfo.GetCustomAttribute<SerializeAsBase64Attribute>() != null;
SerializeNull = memberInfo.GetCustomAttribute<SerializeNullAttribute>() != null;
HasParameterAttribute = memberInfo.GetCustomAttribute<ParameterAttribute>() != null;
}
示例4: GetName
public string GetName(MemberInfo member, bool includeProtocolProps = true)
{
Guard.ArgumentNotNull(member, "member");
if (includeProtocolProps)
{
var protocolAttr = member.GetCustomAttribute<SDataProtocolPropertyAttribute>();
if (protocolAttr != null)
{
var name = protocolAttr.Value != null ? protocolAttr.Value.ToString() : member.Name;
if (char.IsUpper(name[0]))
{
name = char.ToLowerInvariant(name[0]) + name.Substring(1);
}
return "$" + name;
}
}
#if !NET_2_0
var contractAttr = member.GetCustomAttribute<DataContractAttribute>();
if (contractAttr != null && !string.IsNullOrEmpty(contractAttr.Name))
{
return contractAttr.Name;
}
var memberAttr = member.GetCustomAttribute<DataMemberAttribute>();
if (memberAttr != null && !string.IsNullOrEmpty(memberAttr.Name))
{
return memberAttr.Name;
}
#endif
var elementAttr = member.GetCustomAttribute<XmlElementAttribute>();
if (elementAttr != null && !string.IsNullOrEmpty(elementAttr.ElementName))
{
return elementAttr.ElementName;
}
var attributeAttr = member.GetCustomAttribute<XmlAttributeAttribute>();
if (attributeAttr != null && !string.IsNullOrEmpty(attributeAttr.AttributeName))
{
return attributeAttr.AttributeName;
}
var arrayAttr = member.GetCustomAttribute<XmlArrayAttribute>();
if (arrayAttr != null && !string.IsNullOrEmpty(arrayAttr.ElementName))
{
return arrayAttr.ElementName;
}
var serviceAttr = member.GetCustomAttribute<SDataServiceOperationAttribute>();
if (serviceAttr != null && !string.IsNullOrEmpty(serviceAttr.Name))
{
return serviceAttr.Name;
}
return _transform(member.Name);
}
示例5: GetIndexFieldName
public override string GetIndexFieldName(MemberInfo member)
{
var memberAttribute = GetIndexFieldNameFormatterAttribute(member);
if (memberAttribute != null) return base.GetIndexFieldName(member);
var fieldConfig = member.GetCustomAttribute<SitecoreFieldAttribute>(true);
if (fieldConfig == null && member.DeclaringType != null)
{
var interfaceFromProperty = member.DeclaringType.GetInterfaces().FirstOrDefault(inter => inter.GetProperty(member.Name) != null);
if (interfaceFromProperty != null)
{
fieldConfig = interfaceFromProperty.GetMember(member.Name).First().GetCustomAttribute<SitecoreFieldAttribute>(true);
}
}
if (fieldConfig != null && !string.IsNullOrEmpty(fieldConfig.FieldName))
return base.GetIndexFieldName(fieldConfig.FieldName);
if (fieldConfig == null)
{
var infoConfig = member.GetCustomAttribute<SitecoreInfoAttribute>(true);
if (infoConfig == null && member.DeclaringType != null)
{
var interfaceFromProperty = member.DeclaringType.GetInterfaces().FirstOrDefault(inter => inter.GetProperty(member.Name) != null);
if (interfaceFromProperty != null)
{
infoConfig = interfaceFromProperty.GetMember(member.Name).First().GetCustomAttribute<SitecoreInfoAttribute>(true);
}
}
if (infoConfig != null)
{
switch (infoConfig.Type)
{
case SitecoreInfoType.DisplayName:
return base.GetIndexFieldName(BuiltinFields.DisplayName);
case SitecoreInfoType.FullPath:
return base.GetIndexFieldName(BuiltinFields.FullPath);
case SitecoreInfoType.TemplateId:
return base.GetIndexFieldName(BuiltinFields.Template);
case SitecoreInfoType.TemplateName:
return base.GetIndexFieldName(BuiltinFields.TemplateName);
case SitecoreInfoType.Url:
return base.GetIndexFieldName(BuiltinFields.Url);
case SitecoreInfoType.Version:
return base.GetIndexFieldName(BuiltinFields.Version);
case SitecoreInfoType.Name:
return base.GetIndexFieldName(BuiltinFields.Name);
case SitecoreInfoType.Language:
return base.GetIndexFieldName(BuiltinFields.Language);
}
}
}
return base.GetIndexFieldName(member);
}
示例6: Process
private static void Process(MemberInfo member, ISpecification holder) {
// give priority to Idempotent as more restrictive
if (member.GetCustomAttribute<IdempotentAttribute>() != null) {
FacetUtils.AddFacet(new IdempotentFacet(holder));
}
else if (member.GetCustomAttribute<QueryOnlyAttribute>() != null) {
FacetUtils.AddFacet(new QueryOnlyFacet(holder));
}
}
示例7: Create
public static MetaColumn Create(MemberInfo member)
{
var databaseGeneratedAttr = member.GetCustomAttribute<DatabaseGeneratedAttribute>();
return new MetaColumn
{
Member = member,
ColumnName = GetColumnName(member),
IsKey = member.GetCustomAttribute<KeyAttribute>() != null,
IsIdentity = databaseGeneratedAttr != null && databaseGeneratedAttr.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity,
IsCompute = databaseGeneratedAttr != null && databaseGeneratedAttr.DatabaseGeneratedOption == DatabaseGeneratedOption.Computed,
};
}
示例8: GetColumnName
private static string GetColumnName(MemberInfo member)
{
var columnAttr = member.GetCustomAttribute<ColumnAttribute>();
return columnAttr != null && !string.IsNullOrWhiteSpace(columnAttr.Name)
? columnAttr.Name
: member.Name;
}
示例9: UpdateDefaultValue
private static void UpdateDefaultValue(MemberInfo memberInfo, MetaProperty info)
{
var defaultAttribute = memberInfo.GetCustomAttribute<DefaultValueAttribute>();
if (defaultAttribute == null) return;
info.DefaultValue = defaultAttribute.Value;
}
示例10: GetCommandName
public static string GetCommandName(MemberInfo t)
{
var attr = t.GetCustomAttribute<CommandAttribute>();
if (attr != null)
return attr.Name;
else return null;
}
示例11: HasAttribute
private static bool HasAttribute(MemberInfo mi, object o)
{
if (mi.DeclaringType.GetCustomAttribute<AppSettingAttribute>() != null)
{
return true;
}
return mi.GetCustomAttribute<AppSettingAttribute>() != null;
}
示例12: GetExecutionBrowserMethodLevel
private BrowserTypes GetExecutionBrowserMethodLevel(MemberInfo memberInfo)
{
var executionBrowserAttribute = memberInfo.GetCustomAttribute<ExecutionBrowserAttribute>(true);
if (executionBrowserAttribute != null)
{
return executionBrowserAttribute.BrowserType;
}
return BrowserTypes.NotSet;
}
示例13: SwaggerDtoPropertiesShouldHaveSwaggerPropertyAttribute
public void SwaggerDtoPropertiesShouldHaveSwaggerPropertyAttribute(MemberInfo member)
{
var swaggerProperty = member.GetCustomAttribute<SwaggerPropertyAttribute>();
if (swaggerProperty != null)
{
swaggerProperty.Name.ShouldNotBeNull();
return;
}
var enumValue = member.GetCustomAttribute<SwaggerEnumValueAttribute>();
if (enumValue != null)
{
enumValue.Value.ShouldNotBeNull();
return;
}
throw new Exception(string.Format(
"Member {0} is missing SwaggerProperty- or SwaggerEnumValueAttribute.", GetDisplayName(member)));
}
示例14: GetIdentifier
/// <summary>
/// Gets the XML identifier of the member.
/// </summary>
/// <param name="memberInfo">The information about the member to use.</param>
/// <returns>The XML identifier of the member.</returns>
public static string GetIdentifier(MemberInfo memberInfo)
{
var nameAttribute = memberInfo.GetCustomAttribute<XmlConvertCustomElementAttribute>();
if (nameAttribute != null)
{
return nameAttribute.Name;
}
return memberInfo.Name;
}
示例15: CreateProperty
// Note: this method is called just once for a given property; Newtonsoft serializer caches metadata information,
// so the result is cached and reused. We are not concerned with efficiency here
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
var nodeAttr = member.GetCustomAttribute<NodeAttribute>(inherit: true);
if (nodeAttr != null)
property.PropertyName = nodeAttr.Name;
else if (ChangeToCamelCase)
property.PropertyName = property.PropertyName.ToCamelCase();
return property;
}