コード例 #1
0
        public void AddTypes(params Type[] types)
        {
            var components = types.AsParallel().Select(MakeComponent).ToArray();

            var producerFields = (from component in components.AsParallel()
                                  let type = component.Type
                                             from field in type.GetFields(AllBindingFlags)
                                             where field.HasAttributeRecursive <ProducesAttribute>()
                                             select MakeProducerField(component, field)).ToArray();

            var producerMethods = (from component in components.AsParallel()
                                   let type = component.Type
                                              from method in type.GetMethods(AllBindingFlags)
                                              where method.HasAttributeRecursive <ProducesAttribute>()
                                              select MakeProducerMethod(component, method)).ToArray();

            var producerProperties = (from component in components.AsParallel()
                                      let type = component.Type
                                                 from property in type.GetProperties(AllBindingFlags)
                                                 where property.HasAttributeRecursive <ProducesAttribute>()
                                                 select MakeProducerProperty(component, property)).ToArray();

            foreach (var c in components.Union(producerFields).Union(producerMethods).Union(producerProperties))
            {
                _environment.AddComponent(c);
            }
        }
コード例 #2
0
        public void AddTypes(params Type[] types)
        {
            var annotated = types.Select(ProcessAnnotatedType).Where(x => !x.Annotations.Any <VetoAttribute>()).ToArray();

            var components        = annotated.AsParallel().Select(MakeComponent).ToArray();
            var classes           = components.OfType <ClassComponent>().ToArray();
            var eventObservers    = classes.AsParallel().SelectMany(x => FindEventObservers(x.AnnotatedType, x)).ToArray();
            var exceptionHandlers = classes.AsParallel().SelectMany(FindExceptionHandlers).ToArray();

            var producerFields = (from component in classes.AsParallel()
                                  let type = component.AnnotatedType
                                             from field in type.Fields
                                             where field.Annotations.OfType <ProducesAttribute>().Any()
                                             select(IWeldComponent) new ProducerField(component, field, _manager)).ToArray();

            var producerMethods = (from component in classes.AsParallel()
                                   let type = component.AnnotatedType
                                              from method in type.Methods
                                              where method.Annotations.OfType <ProducesAttribute>().Any()
                                              select(IWeldComponent) new ProducerMethod(component, method, _manager)).ToArray();

            var producerProperties = (from component in classes.AsParallel()
                                      let type = component.AnnotatedType
                                                 from property in type.Properties
                                                 where property.Annotations.OfType <ProducesAttribute>().Any()
                                                 select(IWeldComponent) new ProducerProperty(component, property.Property, property.Annotations, _manager)).ToArray();

            foreach (var c in components.Union(producerFields).Union(producerMethods).Union(producerProperties))
            {
                _environment.AddComponent(c);
            }

            foreach (var observer in eventObservers)
            {
                _environment.AddObserver(observer);
            }
            foreach (var handler in exceptionHandlers)
            {
                _environment.AddExceptionHandlers(handler);
            }
        }