本文整理汇总了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;
}
}
示例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);
}
}
示例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));
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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}";
}
示例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);
}
示例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
}
示例12: GetClassName
internal static String GetClassName(TypeInfo type)
{
var attribute = type.GetCustomAttribute<AVClassNameAttribute>();
return attribute != null ? attribute.ClassName : null;
}
示例13: GetLoginType
private static LoginType GetLoginType(TypeInfo typeInfo)
{
return typeInfo.GetCustomAttribute<AuthoAttribution>().LoginType;
}
示例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;
}
示例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;
}