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


C# Type.HasAttribute方法代码示例

本文整理汇总了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));
 }
开发者ID:nishantkagrawal,项目名称:TrainingOct15,代码行数:16,代码来源:AutomappingConfiguration.cs

示例2: Guard

        private void Guard(Type sourceType)
        {
            bool isSnapshotable = typeof(AggregateRoot).IsAssignableFrom(sourceType) && sourceType.HasAttribute<DynamicSnapshotAttribute>();

            if (!isSnapshotable)
                throw new DynamicSnapshotNotSupportedException() { AggregateType = sourceType };
        }
开发者ID:VincentSchippefilt,项目名称:ncqrs,代码行数:7,代码来源:DynamicSnapshotTypeBuilder.cs

示例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);
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:25,代码来源:OracleEnumConverter.cs

示例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;
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:25,代码来源:OracleEnumConverter.cs

示例5: DoesAggregateSupportsSnapshot

        public bool DoesAggregateSupportsSnapshot(Type aggregateType, Type snapshotType)
        {
            bool hasAttribute = aggregateType.HasAttribute<DynamicSnapshotAttribute>();
            bool doesSupportSnapshot = snapshotType.Name == SnapshotNameGenerator.Generate(aggregateType);

            return hasAttribute && doesSupportSnapshot;
        }
开发者ID:VincentSchippefilt,项目名称:ncqrs,代码行数:7,代码来源:AggregateSupportsDynamicSnapshotValidator.cs

示例6: GetCommandName

 string GetCommandName(Type commandType)
 {
     string defaultName = commandType.Name.Replace("Command", "");
     string commandName = commandType.HasAttribute<CommandNameAttribute>() ?
         commandType.GetAttribute<CommandNameAttribute>().Name :
         defaultName;
     return commandName;
 }
开发者ID:subdigital,项目名称:Experiments,代码行数:8,代码来源:CommandsModule.cs

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

示例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;
            }
        }
开发者ID:VincentSchippefilt,项目名称:ncqrs,代码行数:11,代码来源:SnapshotableField.cs

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

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

示例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;
        }
开发者ID:kingreatwill,项目名称:fubumvc,代码行数:17,代码来源:ConfigurationActionSet.cs

示例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;
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:21,代码来源:SpecialConverters.cs

示例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);
      }
 }
开发者ID:the-dargon-project,项目名称:ryu,代码行数:21,代码来源:Activator.cs

示例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();
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:23,代码来源:SpecialConverters.cs

示例15: Matches

 public bool Matches(Type type)
 {
     return type.CanBeCastTo<DomainEntity>() && !type.HasAttribute<IgnoreEntityInBindingAttribute>();
 }
开发者ID:pjdennis,项目名称:fubumvc,代码行数:4,代码来源:EntityModelBinder.cs


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