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


C# TypeInfo.GetCustomAttribute方法代码示例

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


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

示例1: GetComponentFullName

        public static string GetComponentFullName(TypeInfo componentType)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            var attribute = componentType.GetCustomAttribute<ViewComponentAttribute>();
            if (!string.IsNullOrEmpty(attribute?.Name))
            {
                return attribute.Name;
            }

            // If the view component didn't define a name explicitly then use the namespace + the
            // 'short name'.
            var shortName = GetShortNameByConvention(componentType);
            if (string.IsNullOrEmpty(componentType.Namespace))
            {
                return shortName;
            }
            else
            {
                return componentType.Namespace + "." + shortName;
            }
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:25,代码来源:ViewComponentConventions.cs

示例2: Build

        private HarshContentTypeId Build(TypeInfo t)
        {
            if (t.AsType() == typeof(HarshEntity))
            {
                // don't recurse up to Object. we should never get 
                // here anyway, since entities are supposed to inherit from
                // something with an absolute ID specified,
                // not directly from the HarshEntity class. 
                return null;
            }

            var cta = t.GetCustomAttribute<ContentTypeAttribute>(inherit: false);

            if (cta == null)
            {
                if (t == _entityTypeInfo)
                {
                    throw Logger.Fatal.InvalidOperationFormat(
                        SR.ContentTypeIdBuilder_NoContentTypeAttribute,
                        t.FullName
                    );
                }
                else
                {
                    throw Logger.Fatal.InvalidOperationFormat(
                        SR.ContentTypeIdBuilder_NoContentTypeAttributeBaseClass,
                        t.FullName,
                        _entityTypeInfo.FullName
                    );
                }
            }

            var ctid = HarshContentTypeId.Parse(cta.ContentTypeId);

            if (ctid.IsAbsolute)
            {
                // an absolute ID. do not recurse further up the
                // class hierarchy, take it as it is
                return ctid;
            }
            else
            {
                // not an absolute ID, append the parent type ID first
                var result = Build(t.BaseType.GetTypeInfo());

                if (result == null)
                {
                    throw Logger.Fatal.InvalidOperationFormat(
                        SR.ContentTypeIdBuilder_NoAbsoluteIDInHierarchy,
                        _entityTypeInfo.FullName
                    );
                }

                return result.Append(ctid);
            }
        }
开发者ID:NaseUkolyCZ,项目名称:HarshPoint,代码行数:56,代码来源:ContentTypeIdBuilder.cs

示例3: AllPublicConcreteTypesShouldBeAnnotatedWithDebuggerDisplay

        public void AllPublicConcreteTypesShouldBeAnnotatedWithDebuggerDisplay(TypeInfo type)
        {
            var attribute = type.GetCustomAttribute<DebuggerDisplayAttribute>(false);

            Assert.Equal("{DebuggerDisplay, nq}", attribute.Value);

            var debuggerDisplay = type.GetDeclaredProperty("DebuggerDisplay");

            Assert.False(debuggerDisplay.GetAccessors().Any(x => x.IsPublic));
        }
开发者ID:MinistroFx,项目名称:Ministro,代码行数:10,代码来源:ConventionTests.cs

示例4: TestClassInfo

        public TestClassInfo(TypeInfo info) {
 
            if (!info.IsPublic || !info.IsClass) return;
            var attr = info.GetCustomAttribute(typeof(TestAttribute)) as TestAttribute;
            if (attr != null) {
                this.IsValid = true;
                this.TestClassType = info;
                this.Description = attr.Description;
            }
            
        }
开发者ID:yanyitec,项目名称:Yanyitec,代码行数:11,代码来源:TestClassInfo.cs

示例5: IsAnonymousType

 private static bool IsAnonymousType(Type t, TypeInfo ti)
 {
     // This is not a perfect way to detect anonymous classes since they are a compiler feature and not a CLR feature.
     // It is probably good enough though.
     // See also Jon Skeets exhaustive answer on anonymous classes: http://stackoverflow.com/a/315186/271746
     return
         t.Namespace == null &&
         ti.IsPublic == false &&
         t.IsNested == false &&
         ti.IsGenericType &&
         ti.IsSealed &&
         ti.GetCustomAttribute<CompilerGeneratedAttribute>() != null;
 }
开发者ID:wallymathieu,项目名称:SillyXml,代码行数:13,代码来源:XmlSerializer.cs

示例6: CreateGroup

 private static TestGroup CreateGroup(TypeInfo type)
 {
     TestGroup group = new TestGroup();
     group.Name = type.Name;
     group.Tags.Add(type.Name);
     group.Tags.Add(type.FullName);
     if (type.GetCustomAttribute<FunctionalTestAttribute>(true) != null)
     {
         group.Tags.Add("Functional");
     }
     foreach (TagAttribute attr in type.GetCustomAttributes<TagAttribute>(true))
     {
         group.Tags.Add(attr.Tag);
     }
     return group;
 }
开发者ID:TroyBolton,项目名称:azure-mobile-services,代码行数:16,代码来源:TestDiscovery.cs

示例7: ProcessType

        public void ProcessType(IContainerConfiguration container, TypeInfo type)
        {
            var settingsAttribute = type.GetCustomAttribute<SettingsAttribute>();
            if (settingsAttribute != null)
            {
                var settingsType = type.AsType();
                var settingsScope = settingsAttribute.Scope;
                var activatorConfiguration = new SettingsActivatorConfiguration(settingsScope, settingsType);

                container.Register(activatorConfiguration);
            }

            foreach (var serviceType in type.ImplementedInterfaces)
            {
                ProcessServiceType(container, type, serviceType);
            }
        }
开发者ID:tobper,项目名称:Domo,代码行数:17,代码来源:SettingsScanConvention.cs

示例8: GetWidgetName

        /// <summary>
        /// Gets the widget name for the given widget type.
        /// </summary>
        /// <param name="widgetType">The widget type.</param>
        /// <returns>The widget name.</returns>
        public static string GetWidgetName(TypeInfo widgetType)
        {
            if (widgetType == null)
            {
                throw new ArgumentNullException(nameof(widgetType));
            }

            var attr = widgetType.GetCustomAttribute<WidgetAttribute>();
            if (attr != null && !string.IsNullOrEmpty(attr.Name))
            {
                var idx = attr.Name.LastIndexOf('.');
                if (idx >= 0)
                {
                    return attr.Name.Substring(idx + 1);
                }

                return attr.Name;
            }

            return GetShortNameByConvention(widgetType);
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:26,代码来源:WidgetConventions.cs

示例9: GetWidgetFullName

        /// <summary>
        /// Gets the widget full name for the given widget type.
        /// </summary>
        /// <param name="widgetType">The widget type.</param>
        /// <returns>The widget full name.</returns>
        public static string GetWidgetFullName(TypeInfo widgetType)
        {
            if (widgetType == null)
            {
                throw new ArgumentNullException(nameof(widgetType));
            }

            var attr = widgetType.GetCustomAttribute<WidgetAttribute>();
            if (attr != null && !string.IsNullOrEmpty(attr.Name))
            {
                return attr.Name;
            }

            var shortName = GetShortNameByConvention(widgetType);
            if (string.IsNullOrEmpty(widgetType.Namespace))
            {
                return shortName;
            }

            return $"{widgetType.Namespace}.{shortName}";
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:26,代码来源:WidgetConventions.cs

示例10: GetComponentName

        public static string GetComponentName(TypeInfo componentType)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(componentType));
            }

            var attribute = componentType.GetCustomAttribute<ViewComponentAttribute>();
            if (attribute != null && !string.IsNullOrEmpty(attribute.Name))
            {
                var separatorIndex = attribute.Name.LastIndexOf('.');
                if (separatorIndex >= 0)
                {
                    return attribute.Name.Substring(separatorIndex + 1);
                }
                else
                {
                    return attribute.Name;
                }
            }

            return GetShortNameByConvention(componentType);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:23,代码来源:ViewComponentConventions.cs

示例11: HasJsonUseTypeHintAttribute

		public static bool HasJsonUseTypeHintAttribute ( TP tp ) {
#if WINDOWS_STORE
			return tp.GetCustomAttribute<JsonUseTypeHintAttribute> (true) != null;
#else
			return tp.GetCustomAttributes(typeof(JsonUseTypeHintAttribute),true).Length != 0;
#endif
		}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:7,代码来源:TypeCoercionUtility.cs

示例12: GetClassName

 internal static String GetClassName(TypeInfo type)
 {
     var attribute = type.GetCustomAttribute<AVClassNameAttribute>();
       return attribute != null ? attribute.ClassName : null;
 }
开发者ID:wujun4code,项目名称:Parse-SDK-dotNET,代码行数:5,代码来源:ObjectSubclassInfo.cs

示例13: GetLoginType

 private static LoginType GetLoginType(TypeInfo typeInfo)
 {
     return typeInfo.GetCustomAttribute<AuthoAttribution>().LoginType;
 }
开发者ID:xuchong7,项目名称:UWP_ZhiHuRiBao,代码行数:4,代码来源:AuthorizationHelper.cs

示例14: IsWidget

        /// <summary>
        /// Determines if the given type represents a widget.
        /// </summary>
        /// <param name="typeInfo">The candidate type.</param>
        /// <returns>True if the candidate type represents a widget, otherwise false.</returns>
        public static bool IsWidget(TypeInfo typeInfo)
        {
            if (!typeInfo.IsClass
                || !typeInfo.IsPublic
                || typeInfo.IsAbstract
                || typeInfo.ContainsGenericParameters)
            {
                return false;
            }

            return typeInfo.Name.EndsWith(WidgetSuffix, StringComparison.OrdinalIgnoreCase)
                || typeInfo.GetCustomAttribute<WidgetAttribute>() != null;
        }
开发者ID:Antaris,项目名称:AspNetCore.Mvc.Widgets,代码行数:18,代码来源:WidgetConventions.cs

示例15: IsEligiblePart

 /// <summary>
 /// Determines whether the provided type info is an eligible part.
 /// </summary>
 /// <param name="typeInfo">The type information.</param>
 /// <returns>
 /// <c>true</c> if the type information is an eligible part, otherwise <c>false</c>.
 /// </returns>
 private bool IsEligiblePart(TypeInfo typeInfo)
 {
     return typeInfo.IsClass && !typeInfo.IsAbstract && typeInfo.GetCustomAttribute<ExcludeFromCompositionAttribute>() == null;
 }
开发者ID:raimu,项目名称:kephas,代码行数:11,代码来源:AppServiceConventionsRegistrarBase.cs


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