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


C# Type.GetAttributes方法代码示例

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


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

示例1: FindIntroductionAspects

 private IEnumerable<IIntroductionAspect> FindIntroductionAspects(Type type)
 {
     return (from item in type.GetAttributes<IntroductionAspectAttribute>(true)
             let typeFilter = new PredicateTypeFilter(t => t == type)
             let advice = new IntroductionAdvice(item.Types)
             select new IntroductionAspect(typeFilter, advice));
 }
开发者ID:happyframework,项目名称:Happy.Ioc,代码行数:7,代码来源:ServiceLocatorAspectsFinder.cs

示例2: RegisterComponent

        /// <summary>
        ///   Register a new component.
        /// </summary>
        /// <param name="builder"> autofac container builder </param>
        /// <param name="type"> Type to register </param>
        public virtual void RegisterComponent(ContainerBuilder builder, Type type)
        {
            if (builder == null) throw new ArgumentNullException("builder");
            if (type == null) throw new ArgumentNullException("type");

            _builder = builder;
            var attribute = type.GetAttributes<ComponentAttribute>(false).Single();

            var lifetime = attribute.Lifetime == Lifetime.Default ? DefaultLifetime : attribute.Lifetime;

            switch (lifetime)
            {
                case Lifetime.Transient:
                    RegisterTransient(type, attribute);
                    break;
                case Lifetime.Singleton:
                    RegisterSingleton(type, attribute);
                    break;
                case Lifetime.Scoped:
                    RegisterScoped(type, attribute);
                    break;
                default:
                    throw new InvalidOperationException(
                        string.Format(
                            "Either the [Component] attribute on {0} or the ComponentRegistrar.DefaultLifetime must have been specified.",
                            type.FullName));
            }
        }
开发者ID:sogeti-se,项目名称:Sogeti.Pattern,代码行数:33,代码来源:ComponentRegistrar.cs

示例3: AttributesFor

 public IEnumerable<IFilterAttribute> AttributesFor(Type type)
 {
     return withCache(new Signature(type), () =>
     {
         return type.GetAttributes<IFilterAttribute>();
     });
 }
开发者ID:NiSHoW,项目名称:FrameLogCustom,代码行数:7,代码来源:FilterAttributeCache.cs

示例4: AddSideEffectDeclaration

        private void AddSideEffectDeclaration(Type type)
        {
            IEnumerable<SideEffectDeclaration> sideEffects = from sideEffectAttribute in type.GetAttributes<SideEffectsAttribute>()
                                                             from sideEffectType in sideEffectAttribute.SideEffectTypes
                                                             select new SideEffectDeclaration(sideEffectType, type);

            this.sideEffectDeclarations.AddRange(sideEffects);
        }
开发者ID:attila3453,项目名称:alsing,代码行数:8,代码来源:SideEffectsDeclaration.cs

示例5: AddConstraintDeclarations

 private void AddConstraintDeclarations(Type type)
 {
     IEnumerable<ConstraintAttribute> annotations = type.GetAttributes<ConstraintAttribute>();
     foreach (ConstraintAttribute annontation in annotations)
     {
         this.constraints.Add(new ConstraintDeclaration(annontation, type));
     }
 }
开发者ID:attila3453,项目名称:alsing,代码行数:8,代码来源:ConstraintsModel.cs

示例6: IsPersistent

 public bool IsPersistent(Type messageType)
 {
     Preconditions.CheckNotNull(messageType, "messageType");
     var deliveryModeAttribute = messageType.GetAttributes<DeliveryModeAttribute>().FirstOrDefault();
     if (deliveryModeAttribute != null)
         return deliveryModeAttribute.IsPersistent;
     return connectionConfiguration.PersistentMessages;
 }
开发者ID:autotagamerica,项目名称:EasyNetQ,代码行数:8,代码来源:DeliveryModeStrategy.cs

示例7: CreateHistoryInfo

 public HistoryInfo CreateHistoryInfo(Type decoratedType)
 {
     return new HistoryInfo(
         _historyKey,
         ((ComponentRegistrationBase)decoratedType.GetAttributes<ComponentRegistrationBase>(true)
             .FirstOrDefault()
             .GetComponentInfo(decoratedType)).Service
         );
 }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:9,代码来源:HistoryKeyAttribute.cs

示例8: GetXmlSerializer

		XmlObjectSerializer GetXmlSerializer(Type type)
		{
			if (type.GetAttributes<DataContractAttribute>(false).Length > 0)
			{
				return new DataContractSerializer(type);
			}
			
			return new NetDataContractSerializer();
		}
开发者ID:cdrnet,项目名称:Lokad.Cloud,代码行数:9,代码来源:CloudFormatter.cs

示例9: AddConcernDeclarations

        private static void AddConcernDeclarations(Type type, List<ConcernDeclaration> concerns)
        {
            IEnumerable<ConcernsAttribute> attributes = type.GetAttributes<ConcernsAttribute>();

            IEnumerable<ConcernDeclaration> types = from attribute in attributes
                                                    from concernType in attribute.ConcernTypes
                                                    select new ConcernDeclaration(concernType, type);

            concerns.AddRange(types);
        }
开发者ID:attila3453,项目名称:alsing,代码行数:10,代码来源:ConcernsDeclaration.cs

示例10: CreateMetaFromType

		/// <summary>
		///   Creates the meta-info from the specified type.
		/// </summary>
		/// <param name = "implementation">The implementation type.</param>
		/// <returns>The corresponding meta-info.</returns>
		public SynchronizeMetaInfo CreateMetaFromType(Type implementation)
		{
			var syncAttrib = implementation.GetAttributes<SynchronizeAttribute>()[0];
			var metaInfo = new SynchronizeMetaInfo(syncAttrib);

			PopulateMetaInfoFromType(metaInfo, implementation);

			Register(implementation, metaInfo);

			return metaInfo;
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:16,代码来源:SynchronizeMetaInfoStore.cs

示例11: GetConverter

 public static TypeConverter GetConverter(Type type)
 {
     TypeConverter converter;
     if (!Cache.TryGetValue(type, out converter))
     {
         IEnumerable<TypeConverterAttribute> attributes = type.GetAttributes<TypeConverterAttribute>(true);
         if (!attributes.Any<TypeConverterAttribute>())
         {
             return new TypeConverter();
         }
         converter = Activator.CreateInstance(Type.GetType(attributes.First<TypeConverterAttribute>().ConverterTypeName)) as TypeConverter;
         Cache[type] = converter;
     }
     return converter;
 }
开发者ID:BigBri41,项目名称:TWCTVWindowsPhone,代码行数:15,代码来源:TypeDescriptor.cs

示例12: GetConverter

        /// <summary>
        /// Returns a type converter for the specified type.
        /// </summary>
        /// <param name="type">The System.Type of the target component.</param>
        /// <returns>A System.ComponentModel.TypeConverter for the specified type.</returns>
        public static TypeConverter GetConverter(Type type)
        {
            TypeConverter converter;

            if(!Cache.TryGetValue(type, out converter))
            {
                var customAttributes = type.GetAttributes<TypeConverterAttribute>(true);

                if(!customAttributes.Any())
                    return new TypeConverter();

                converter = Activator.CreateInstance(Type.GetType(customAttributes.First().ConverterTypeName)) as TypeConverter;
                Cache[type] = converter;
            }

            return converter;
        }
开发者ID:Klakier,项目名称:Road-Traffic-Simualator,代码行数:22,代码来源:TypeDescriptor.cs

示例13: CreateCore

        /// <summary>
        /// Creates the actual description.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <returns></returns>
        protected virtual IViewModelDescription CreateCore(Type targetType) 
        {
            var customFactory = targetType
                .GetAttributes<IViewModelDescriptionFactory>(true)
                .FirstOrDefault();

            if (customFactory != null)
                return customFactory.Create(targetType);

            var description = new DefaultViewModelDescription(conventionManager, targetType);
            var filters = new FilterManager(targetType, description.TargetType, serviceLocator);
            var actions = actionLocator.Locate(new ActionLocationContext(serviceLocator, targetType, filters));

            description.Filters = filters;
            actions.Apply(description.AddAction);

            return description;
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:23,代码来源:DefaultViewModelDescriptionFactory.cs

示例14: FindPointcutAspects

        private IEnumerable<IAspect> FindPointcutAspects(Type type)
        {

            var typeAspects = (from item in type.GetAttributes<PointcutAspectAttribute>(true)
                               let typeFilter = new PredicateTypeFilter(t => t == type)
                               let pointcut = new Pointcut(typeFilter)
                               select new PointcutAspect(pointcut, item.Advice));

            var mehodAspects = type.GetMethods().SelectMany(method =>
            {
                return (from item in method.GetAttributes<PointcutAspectAttribute>(true)
                        let typeFilter = new PredicateTypeFilter(t => t == type)
                        let methodMatcher = new PredicateMethodMatcher((m, t) =>
                                                                        m.Match(method))
                        let pointcut = new Pointcut(typeFilter, methodMatcher)
                        select new PointcutAspect(pointcut, item.Advice));
            });

            return typeAspects.Concat(mehodAspects);
        }
开发者ID:happyframework,项目名称:Happy.Ioc,代码行数:20,代码来源:ServiceLocatorAspectsFinder.cs

示例15: GetQueueAttribute

 private QueueAttribute GetQueueAttribute(Type messageType)
 {
     var attr = messageType.GetAttributes<QueueAttribute>().FirstOrDefault();
     return attr ?? new QueueAttribute(string.Empty);
 }
开发者ID:autotagamerica,项目名称:EasyNetQ,代码行数:5,代码来源:Conventions.cs


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