Ejemplo n.º 1
0
        internal CompositeTypeWeaverBuilder(Type compositeType, INCopRegistry registry)
        {
            var mixinsMap              = new MixinsMap(compositeType);
            var aspectMappedMembers    = new AspectMemberMapper(compositeType, mixinsMap);
            var aspectsMap             = new AspectsMap(compositeType, aspectMappedMembers);
            var typeDefinitionWeaver   = new MixinsTypeDefinitionWeaver(compositeType, mixinsMap);
            var compositeMappedMembers = new CompositeMemberMapper(aspectsMap, aspectMappedMembers);
            var typeDefinition         = typeDefinitionWeaver.Weave();

            builder = new MixinsTypeWeaverBuilder(compositeType, typeDefinition, registry);

            mixinsMap.ForEach(map => {
                builder.Add(map);
            });

            compositeMappedMembers.Methods.ForEach(compositeMethodMap => {
                var methodBuilder = new CompositeMethodWeaverBuilder(compositeMethodMap, typeDefinition);

                builder.Add(methodBuilder);
            });

            compositeMappedMembers.Properties.ForEach(compositePropertyMap => {
                var propertyBuilder = new CompositePropertyWeaverBuilder(compositePropertyMap, typeDefinition);

                builder.Add(propertyBuilder);
            });
        }
Ejemplo n.º 2
0
        public void Run()
        {
            ITypeWeaver            bulkWeaving              = null;
            var                    compositesQueue          = new Queue <ITypeWeaver>();
            AspectsAttributeWeaver aspectRepository         = null;
            AspectArgsMapperWeaver aspectArgsMapperWeaver   = null;
            var                    aspectDefinitionsTypeSet = new HashSet <Type>();

            var composites = typeFactory.Types.Select(type => new {
                Type       = type,
                Attributes = type.GetCustomAttributesArray <CompositeAttribute>()
            })
                             .Where(composite => composite.Attributes.Length > 0);

            var compositeWeavingSettings = composites.ToList(composite => {
                var compositeType       = composite.Type;
                var mixinsMap           = new MixinsMap(compositeType);
                var aspectMappedMembers = new AspectMemberMapper(compositeType, mixinsMap);
                var aspectsMap          = new AspectsMap(aspectMappedMembers);

                var aspectDefinitionsTypes = aspectsMap.SelectMany(aspectMap => {
                    return(aspectMap.Aspects.Select(aspectDefinition => {
                        return aspectDefinition.Aspect.AspectType;
                    }));
                });

                aspectDefinitionsTypeSet.AddRange(aspectDefinitionsTypes);

                return(new CompositeWeavingSettingsImpl {
                    Registry = registry,
                    MixinsMap = mixinsMap,
                    AspectsMap = aspectsMap,
                    CompositeType = compositeType,
                    AspectMemebrsCollection = aspectMappedMembers
                });
            });

            aspectArgsMapperWeaver = new AspectArgsMapperWeaver();
            aspectRepository       = new AspectsAttributeWeaver(aspectDefinitionsTypeSet);
            compositesQueue.Enqueue(aspectArgsMapperWeaver);
            compositesQueue.Enqueue(aspectRepository);

            compositeWeavingSettings.ForEach(compositeSettings => {
                IBuilder <ITypeWeaver> builder = null;

                compositeSettings.AspectRepository = aspectRepository;
                compositeSettings.AspectArgsMapper = aspectArgsMapperWeaver;
                builder = new CompositeTypeWeaverBuilder(compositeSettings);

                compositesQueue.Enqueue(builder.Build());
            });

            bulkWeaving = new BulkWeaving(compositesQueue);
            bulkWeaving.Weave();
        }