コード例 #1
0
        public void Execute(TypeContextFactory factory)
        {
            foreach (var assembly in _assemblies)
            {
                List <Type> foundTypes = new List <Type>();

                if (_types != null)
                {
                    foreach (var type in _types)
                    {
                        foundTypes.AddRange(assembly.GetTypes().Where(x => !x.IsAbstract && x.CanBeCastTo(type)));
                    }
                }
                else
                {
                    var badNames = new[] { "System", "Microsoft" };

                    foundTypes.AddRange(assembly.GetTypes().Where(x => !x.IsAbstract && !x.IsInterface && !badNames.Any(b => x.Name.StartsWith(b))));
                }

                foreach (var foundType in foundTypes)
                {
                    _action.Invoke(foundType, factory);
                }
            }
        }
コード例 #2
0
 public override object Instance(TypeContextFactory factory, IBaseTypeAction typeAction)
 {
     lock (_lock)
     {
         return(HttpContext.Current.Session[typeAction.InterfaceType.Name] ??
                (HttpContext.Current.Session[typeAction.InterfaceType.Name] = base.Instance(factory, typeAction)));
     }
 }
コード例 #3
0
        private void ProcessAspectDefinitions(MethodDefinition targetMethod,
                                              string targetName,
                                              IEnumerable <AspectDefinition> aspectDefinitions)
        {
            var filteredDefinitions = aspectDefinitions.Where(def => CheckFilter(targetMethod, targetName, def));
            var mergedDefinitions   = MergeAspectDefinitions(filteredDefinitions);

            var contexts = mergedDefinitions
                           .Select(def =>
            {
                var adviceClassType = def.AdviceClassType;

                var aspectScope = targetMethod.IsStatic ? AspectScope.Type : AspectScope.Instance;
                if (adviceClassType.CustomAttributes.HasAttributeOfType <AspectScopeAttribute>())
                {
                    aspectScope = (AspectScope)adviceClassType.CustomAttributes.GetAttributeOfType <AspectScopeAttribute>().ConstructorArguments[0].Value;
                }

                var aspectContext = new AspectContext()
                {
                    TargetName         = targetName,
                    TargetTypeContext  = TypeContextFactory.GetOrCreateContext(targetMethod.DeclaringType),
                    AdviceClassType    = adviceClassType,
                    AdviceClassScope   = aspectScope,
                    AspectRoutableData = def.RoutableData == null ? new CustomAttribute[] { } : def.RoutableData.ToArray()
                };

                return(aspectContext);
            })
                           .Where(ctx => _processors.Any(p => p.CanProcess(ctx.AdviceClassType)))
                           .ToList();

            Validator.ValidateAspectContexts(contexts);

            foreach (var context in contexts)
            {
                var targetMethodContext = MethodContextFactory.GetOrCreateContext(targetMethod);
                context.TargetMethodContext = targetMethodContext; //setting it here for better performance

                foreach (var processor in _processors)
                {
                    if (processor.CanProcess(context.AdviceClassType))
                    {
                        processor.Process(context);
                    }
                }
            }
        }
コード例 #4
0
 public void Execute(TypeContextFactory factory)
 {
     factory.Add(new TypeAction <UsedForScannerOnly, UsedForScannerOnly>());
 }
コード例 #5
0
 public object Instance(TypeContextFactory factory)
 {
     return(RegisteredTypeAction.LifeSpan.Instance(factory, RegisteredTypeAction));
 }
コード例 #6
0
ファイル: TypeContext.cs プロジェクト: tomlazelle/TypeCreator
 public TypeContext()
 {
     _factory = new TypeContextFactory();
     _factory.Add(new TypeAction <ITypeContext, TypeContext>(this));
 }