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


C# MemberInfo.GetCustomAttribute方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:xqiu,项目名称:azure-mobile-services,代码行数:30,代码来源:SerializableMember.cs

示例2: MemberData

        public MemberData(Type type, MemberInfo memberInfo)
        {
            Type = type;

            ServiceKey = memberInfo.GetCustomAttribute<ServiceKeyAttribute>()?.Key;
            InjectableAttribute = memberInfo.GetCustomAttribute<InjectableAttribute>();
        }
开发者ID:ReMinoer,项目名称:Diese,代码行数:7,代码来源:MemberData.cs

示例3: PropertyOrField

 protected PropertyOrField(MemberInfo memberInfo)
 {
     MemberInfo = memberInfo;
     Base64Encoded = memberInfo.GetCustomAttribute<SerializeAsBase64Attribute>() != null;
     SerializeNull = memberInfo.GetCustomAttribute<SerializeNullAttribute>() != null;
     HasParameterAttribute = memberInfo.GetCustomAttribute<ParameterAttribute>() != null;
 }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:7,代码来源:PropertyOrField.cs

示例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);
            }
开发者ID:nicocrm,项目名称:DotNetSDataClient,代码行数:58,代码来源:NamingScheme.cs

示例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);
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:57,代码来源:GlassLuceneFieldNameTranslator.cs

示例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));
     }
 }
开发者ID:Robin--,项目名称:NakedObjectsFramework,代码行数:9,代码来源:PotencyAnnotationFacetFactory.cs

示例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,
            };
        }
开发者ID:xiaokangz,项目名称:MyQuery,代码行数:13,代码来源:Metadata.cs

示例8: GetColumnName

 private static string GetColumnName(MemberInfo member)
 {
     var columnAttr = member.GetCustomAttribute<ColumnAttribute>();
     return columnAttr != null && !string.IsNullOrWhiteSpace(columnAttr.Name)
                         ? columnAttr.Name
                         : member.Name;
 }
开发者ID:xiaokangz,项目名称:MyQuery,代码行数:7,代码来源:Metadata.cs

示例9: UpdateDefaultValue

		private static void UpdateDefaultValue(MemberInfo memberInfo, MetaProperty info)
		{
			var defaultAttribute = memberInfo.GetCustomAttribute<DefaultValueAttribute>();
			if (defaultAttribute == null) return;

			info.DefaultValue = defaultAttribute.Value;
		}
开发者ID:s-KaiNet,项目名称:Untech.SharePoint,代码行数:7,代码来源:MetaProperty.cs

示例10: GetCommandName

 public static string GetCommandName(MemberInfo t)
 {
     var attr = t.GetCustomAttribute<CommandAttribute>();
     if (attr != null)
         return attr.Name;
     else return null;
 }
开发者ID:mogliang,项目名称:Generic-WPF-Form-Controls,代码行数:7,代码来源:CommandAttribute.cs

示例11: HasAttribute

        private static bool HasAttribute(MemberInfo mi, object o)
        {
            if (mi.DeclaringType.GetCustomAttribute<AppSettingAttribute>() != null)
            {
                return true;
            }

            return mi.GetCustomAttribute<AppSettingAttribute>() != null;
        }
开发者ID:drwill,项目名称:mash,代码行数:9,代码来源:PrintHelper.cs

示例12: GetExecutionBrowserMethodLevel

 private BrowserTypes GetExecutionBrowserMethodLevel(MemberInfo memberInfo)
 {
     var executionBrowserAttribute = memberInfo.GetCustomAttribute<ExecutionBrowserAttribute>(true);
     if (executionBrowserAttribute != null)
     {
         return executionBrowserAttribute.BrowserType;
     }
     return BrowserTypes.NotSet;
 }
开发者ID:kennedykinyanjui,项目名称:Projects,代码行数:9,代码来源:BrowserLaunchTestBehaviorObserver.cs

示例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)));
        }
开发者ID:jamestupper,项目名称:Nancy.Swagger,代码行数:19,代码来源:SwaggerPropertyConventionTests.cs

示例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;
        }
开发者ID:hughbe,项目名称:xml.net,代码行数:15,代码来源:Utilities.cs

示例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;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:12,代码来源:NodeNameContractResolver.cs


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