Ejemplo n.º 1
0
        /**
         * Rellenamos el DTO con los valores que tenga asociado ese tipo.
         */
        private ComponentModelDTO fillDTO(Type type)
        {
            ComponentModelDTO  componentModelDTO  = (ComponentModelDTO)FactoryDTO.Instance.Create(CreateDTO.ComponentModel);
            ComponentAttribute componentAttribute = (ComponentAttribute)(type.GetCustomAttributes(typeof(ComponentAttribute), true)[0]);

            componentModelDTO.ComponentClassName        = type.FullName;
            componentModelDTO.ComponentName             = componentAttribute.ComponentName;
            componentModelDTO.ExceptionManagerClassName = componentAttribute.ExceptionManager;

            return(componentModelDTO);
        }
Ejemplo n.º 2
0
        public ICollection ProcessAssembly(Assembly assembly)
        {
            logger.Debug("Assembly to Process: " + assembly.FullName);
            ArrayList list = new ArrayList();

            //VAmos a comprobar que no se procesen ensamblados que sean del
            //core.

            if (assembly.FullName.StartsWith("mscorlib") ||
                assembly.FullName.StartsWith("System")
                )
            {
                logger.Debug("Core Assembly detected: " + assembly.FullName);
                logger.Debug("* SKIPPING * Core Assembly: " + assembly.FullName);
                return(list);
            }

            Type[] types = assembly.GetTypes();
            //TODO filter with memberfilter :)
            for (int i = 0; i < types.Length; i++)
            {
                //Debe ser una subclase de DefaultComponentModel (implemente
                //IComponentModel)
                if (types[i].IsSubclassOf(typeof(DefaultComponentModel)))
                {
                    Attribute[] attributes = (Attribute[])types[i].GetCustomAttributes(typeof(ComponentAttribute), true);
                    if (attributes.Length.Equals(1))
                    {
                        //Deberiamos registrar el tipo en el Container. Y
                        //parsear la información para rellenar su DTO.
                        ComponentModelDTO     componentModelDTO     = this.fillDTO(types[i]);
                        ConstructorInfo       constructorInfo       = types[i].GetConstructor(null);
                        DefaultComponentModel defaultComponentModel = (DefaultComponentModel)constructorInfo.Invoke(null);
                        //Seteamos el vo con reflection y mantener oculto el
                        //resto.
                        FieldInfo voFieldInfo = types[i].GetField("componentModelDTO", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField);  // | BindingFlags.DeclaredOnly);
                        //if (voFieldInfo == null)
                        //    Console.WriteLine ("FieldInfo == null.");
                        voFieldInfo.SetValue(defaultComponentModel, componentModelDTO);
                        list.Add(defaultComponentModel);
                    }
                }
            }
            return((ICollection)list);
        }