本文整理汇总了C#中System.Type.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Type.HasAttribute方法的具体用法?C# Type.HasAttribute怎么用?C# Type.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.HasAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldMap
/// <summary>
/// Maps all Models implementing IEntity, and not implementing IFluentIgnore and IMapByCode
/// </summary>
/// <param name="type">
/// The type of model currently being checked
/// </param>
/// <returns>
/// Whether the current type should be automapped or not
/// </returns>
public override bool ShouldMap(Type type)
{
return
type.GetInterface(typeof(IEntity).FullName) != null &&
!type.HasAttribute(typeof(FluentIgnoreAttribute)) &&
!type.HasAttribute(typeof(MapByCodeAttribute));
}
示例2: Guard
private void Guard(Type sourceType)
{
bool isSnapshotable = typeof(AggregateRoot).IsAssignableFrom(sourceType) && sourceType.HasAttribute<DynamicSnapshotAttribute>();
if (!isSnapshotable)
throw new DynamicSnapshotNotSupportedException() { AggregateType = sourceType };
}
示例3: ToQuotedString
public override string ToQuotedString(Type fieldType, object value)
{
if (fieldType.HasAttribute<EnumAsIntAttribute>())
{
return this.ConvertNumber(fieldType.GetEnumUnderlyingType(), value).ToString();
}
if (value is int && !fieldType.IsEnumFlags())
{
value = fieldType.GetEnumName(value);
}
if (fieldType.IsEnum)
{
var enumValue = DialectProvider.StringSerializer.SerializeToString(value);
// Oracle stores empty strings in varchar columns as null so match that behavior here
if (enumValue == null)
return null;
enumValue = DialectProvider.GetQuotedValue(enumValue.Trim('"'));
return enumValue == "''"
? "null"
: enumValue;
}
return base.ToQuotedString(fieldType, value);
}
示例4: ToDbValue
public override object ToDbValue(Type fieldType, object value)
{
if (value is int && !fieldType.IsEnumFlags())
{
value = fieldType.GetEnumName(value);
}
if (fieldType.HasAttribute<EnumAsIntAttribute>())
{
if (value is string)
{
value = Enum.Parse(fieldType, value.ToString());
}
return (int) value;
}
var enumValue = DialectProvider.StringSerializer.SerializeToString(value);
// Oracle stores empty strings in varchar columns as null so match that behavior here
if (enumValue == null)
return null;
enumValue = enumValue.Trim('"');
return enumValue == ""
? null
: enumValue;
}
示例5: DoesAggregateSupportsSnapshot
public bool DoesAggregateSupportsSnapshot(Type aggregateType, Type snapshotType)
{
bool hasAttribute = aggregateType.HasAttribute<DynamicSnapshotAttribute>();
bool doesSupportSnapshot = snapshotType.Name == SnapshotNameGenerator.Generate(aggregateType);
return hasAttribute && doesSupportSnapshot;
}
示例6: GetCommandName
string GetCommandName(Type commandType)
{
string defaultName = commandType.Name.Replace("Command", "");
string commandName = commandType.HasAttribute<CommandNameAttribute>() ?
commandType.GetAttribute<CommandNameAttribute>().Name :
defaultName;
return commandName;
}
示例7: EnsureBehaviorHasBehaviorsAttribute
static void EnsureBehaviorHasBehaviorsAttribute(Type behaviorType)
{
if (!behaviorType.HasAttribute<BehaviorsAttribute>())
{
throw new SpecificationUsageException(
"Behaviors require the BehaviorsAttribute on the type containing the Specifications. Attribute is missing from " +
behaviorType.FullName);
}
}
示例8: GetAll
public static IEnumerable<FieldInfo> GetAll(Type type)
{
while (type != null)
{
if (type.HasAttribute<DynamicSnapshotAttribute>())
foreach (var field in GetSnapshotableFields(type))
yield return field;
type = type.BaseType;
}
}
示例9: ChainForType
public static BehaviorChain ChainForType(Type type)
{
if (type.HasAttribute<UrlPatternAttribute>())
{
var route = type.GetAttribute<UrlPatternAttribute>().BuildRoute(type);
return new RoutedChain(route, type, type);
}
var chain = BehaviorChain.ForResource(type);
chain.IsPartialOnly = true;
return chain;
}
示例10: ControllerInfo
public ControllerInfo(Type type)
{
this.Type = type;
var ms = GetMethods(Type);
DefaultAction = GetDefaultAction(ms);
Actions = GetActions(ms);
IsScaffolding = Type.HasAttribute<ScaffoldingAttribute>(true);
ListStyle = GetListStyle();
Name = GetControllerName();
LowerName = Name.ToLower();
Constructor = ClassHelper.GetConstructorDelegate(Type);
}
示例11: TypeIsUnique
public static bool TypeIsUnique(Type type)
{
if (type.HasAttribute<CanBeMultiplesAttribute>()) return false;
// If it does not have any non-default constructors
if (type.GetConstructors().Any(x => x.GetParameters().Any()))
{
return false;
}
if (type.GetProperties().Any(x => x.CanWrite))
{
return false;
}
return true;
}
示例12: ToQuotedString
public override string ToQuotedString(Type fieldType, object value)
{
var isEnumAsInt = fieldType.HasAttribute<EnumAsIntAttribute>();
if (isEnumAsInt)
return this.ConvertNumber(Enum.GetUnderlyingType(fieldType), value).ToString();
var isEnumFlags = fieldType.IsEnumFlags() ||
(!fieldType.IsEnum() && fieldType.IsNumericType()); //i.e. is real int && not Enum
long enumValue;
if (!isEnumFlags && long.TryParse(value.ToString(), out enumValue))
value = Enum.ToObject(fieldType, enumValue);
var enumString = DialectProvider.StringSerializer.SerializeToString(value);
if (enumString == null || enumString == "null")
enumString = value.ToString();
return !isEnumFlags
? DialectProvider.GetQuotedValue(enumString.Trim('"'))
: enumString;
}
示例13: ActivateActivatorlessType
public object ActivateActivatorlessType(IRyuContainer ryu, Type type)
{
try {
var ctor = type.GetRyuConstructorOrThrow();
var parameters = ctor.GetParameters();
var arguments = parameters.Map(p => ryu.GetOrActivate(p.ParameterType));
var instance = ctor.Invoke(arguments);
if (type.HasAttribute<InjectRequiredFields>()) {
var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
var fieldsToInitialize = type.GetFields(bindingFlags)
.Where(f => f.IsInitOnly && !f.FieldType.IsValueType)
.Where(f => f.GetValue(instance) == null);
foreach (var field in fieldsToInitialize) {
field.SetValue(instance, ryu.GetOrActivate(field.FieldType));
}
}
return instance;
} catch (Exception e) {
throw new RyuActivateException(type, e);
}
}
示例14: ToDbValue
public override object ToDbValue(Type fieldType, object value)
{
var isIntEnum = fieldType.IsEnumFlags() ||
fieldType.HasAttribute<EnumAsIntAttribute>() ||
(!fieldType.IsEnum() && fieldType.IsNumericType()); //i.e. is real int && not Enum
if (isIntEnum && value.GetType().IsEnum())
return Convert.ChangeType(value, Enum.GetUnderlyingType(fieldType));
long enumValue;
if (long.TryParse(value.ToString(), out enumValue))
{
if (isIntEnum)
return enumValue;
value = Enum.ToObject(fieldType, enumValue);
}
var enumString = DialectProvider.StringSerializer.SerializeToString(value);
return enumString != null && enumString != "null"
? enumString.Trim('"')
: value.ToString();
}
示例15: Matches
public bool Matches(Type type)
{
return type.CanBeCastTo<DomainEntity>() && !type.HasAttribute<IgnoreEntityInBindingAttribute>();
}