本文整理汇总了C#中Type.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetCustomAttribute方法的具体用法?C# Type.GetCustomAttribute怎么用?C# Type.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetCustomAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefinition
public static Definition GetDefinition(Type type)
{
var crmEntityAttribute = type.GetCustomAttribute<CrmEntityAttribute>();
if (crmEntityAttribute == null)
{
throw new Exception(string.Format("Type {0} does not have a CrmEntityAttribute defined.", type.Name));
}
return GetDefinition(crmEntityAttribute.EntityName);
}
示例2: PluginTypeIdentifier
/// <summary>
/// Initializes the plugin identifier from a type.
/// </summary>
/// <param name="type">The <see cref="System.Type"/> this identifies.</param>
/// <param name="baseType">The <see cref="System.Type"/> <paramref name="type"/> derives from.</param>
public PluginTypeIdentifier(Type type, Type baseType)
{
if (type == null)
throw new ArgumentNullException("type");
if (baseType == null)
throw new ArgumentNullException("baseType");
BaseType = baseType;
Name = type.Name;
FullName = type.FullName;
DescriptionAttribute description = type.GetCustomAttribute<DescriptionAttribute>();
if (description != null)
Description = description.Description;
DisplayNameAttribute displayName = type.GetCustomAttribute<DisplayNameAttribute>();
if (displayName != null)
DisplayName = displayName.DisplayName;
}
示例3: GetSqlSagaAttributeData
public static SqlSagaAttributeData GetSqlSagaAttributeData(Type sagaType)
{
var attribute = sagaType.GetCustomAttribute<SqlSagaAttribute>(false);
if (attribute == null)
{
throw new Exception($"Expected to find a [{nameof(SqlSagaAttribute)}] on saga '{sagaType.FullName}'.");
}
var tableName = attribute.TableSuffix;
if (tableName == null)
{
tableName = sagaType.Name;
}
return new SqlSagaAttributeData
{
TableSuffix = tableName,
CorrelationProperty = attribute.CorrelationProperty,
TransitionalCorrelationProperty = attribute.TransitionalCorrelationProperty
};
}
示例4: HasFlagsInternal
private static bool HasFlagsInternal(Type type)
{
Contract.Assert(type != null);
FlagsAttribute attribute = type.GetCustomAttribute<FlagsAttribute>(inherit: false);
return attribute != null;
}