Esempio n. 1
0
        internal bool BuildConstructorAttributes(Type type, ref List <Tuple <object, List <Attribute> > > configuredMembers)
        {
            IEnumerable <ConstructorInfo> constructors = type.GetTypeInfo().DeclaredConstructors;

            // First see if any of these constructors have the ImportingConstructorAttribute if so then we are already done
            foreach (var ci in constructors)
            {
                // We have a constructor configuration we must log a warning then not bother with ConstructorAttributes
#if netstandard10
                IEnumerable <Attribute> attributes = ci.GetCustomAttributes(typeof(ImportingConstructorAttribute), false);
#else
                IEnumerable <Attribute> attributes = Attribute.GetCustomAttributes(ci, typeof(ImportingConstructorAttribute), false);
#endif
                if (attributes.Count() != 0)
                {
                    CompositionTrace.Registration_ConstructorConventionOverridden(type);
                    return(true);
                }
            }

            if (_constructorFilter != null)
            {
                ConstructorInfo constructorInfo = _constructorFilter(constructors);
                if (constructorInfo != null)
                {
                    ConfigureConstructorAttributes(constructorInfo, ref configuredMembers, _configureConstuctorImports);
                }
                return(true);
            }
            else if (_configureConstuctorImports != null)
            {
                bool configured = false;
                foreach (var constructorInfo in FindLongestConstructors(constructors))
                {
                    ConfigureConstructorAttributes(constructorInfo, ref configuredMembers, _configureConstuctorImports);
                    configured = true;
                }
                return(configured);
            }
            return(false);
        }
Esempio n. 2
0
        internal bool BuildConstructorAttributes(Type type, ref List <Tuple <object, List <Attribute> > > configuredMembers)
        {
            ConstructorInfo[] constructors = type.GetConstructors();

            // First see if any of these constructors have the ImportingConstructorAttribute if so then we are already done
            foreach (ConstructorInfo ci in constructors)
            {
                // We have a constructor configuration we must log a warning then not bother with ConstructorAttributes
                object[] attributes = ci.GetCustomAttributes(typeof(ImportingConstructorAttribute), false);
                if (attributes.Length != 0)
                {
                    CompositionTrace.Registration_ConstructorConventionOverridden(type);
                    return(true);
                }
            }

            if (_constructorFilter != null)
            {
                ConstructorInfo constructorInfo = _constructorFilter(constructors);
                if (constructorInfo != null)
                {
                    ConfigureConstructorAttributes(constructorInfo, ref configuredMembers, _configureConstuctorImports);
                }

                return(true);
            }
            else if (_configureConstuctorImports != null)
            {
                bool configured = false;
                foreach (ConstructorInfo constructorInfo in FindLongestConstructors(constructors))
                {
                    ConfigureConstructorAttributes(constructorInfo, ref configuredMembers, _configureConstuctorImports);
                    configured = true;
                }

                return(configured);
            }

            return(false);
        }