Example #1
0
        public void AddAssembly(Assembly assembly)
        {
            IEnumerable <Type> publicTypes = assembly.ExportedTypes;

            foreach (Type type in publicTypes)
            {
                ImportConstructorAttribute importConstructorAttribute = type.GetCustomAttribute <ImportConstructorAttribute>();
                bool hasImportedProperties = GetPropertiesWithImportAttribute(type).Any();
                if (importConstructorAttribute != null && hasImportedProperties)
                {
                    throw new IoCContainerException("Class cannot contain ImportConstructorAttribute and ImportAttribute at the same time");
                }

                if (importConstructorAttribute != null ^ hasImportedProperties)
                {
                    AddType(type);
                    continue;
                }

                IEnumerable <ExportAttribute> exportAttributes = type.GetCustomAttributes <ExportAttribute>();
                foreach (ExportAttribute exportAttribute in exportAttributes)
                {
                    AddType(type, exportAttribute.BaseType ?? type);
                }
            }
        }
Example #2
0
 public static bool HasAtributes(this ImportConstructorAttribute constructor)
 {
     return(constructor != null);
 }