Exemplo n.º 1
0
        /// <summary>
        /// The set of parameters returned by this routine is the complete bunch of
        /// parameters for the target constructor.  Their presence guarantees that
        /// they are valid bean references and that they relate to a non-duplicate
        /// well formed constructor.
        /// </summary>
        /// <param name="declaringBeanType">the type which is being scraped</param>
        /// <param name="constructorName">the name of the required constructor - typically ""</param>
        /// <param name="diagnostics">repo for all warnings</param>
        /// <returns>A list of specifications of the parameters of the reqquired constructor
        /// (empty list if none or a default constructor)
        /// </returns>
        public IEnumerable <ParamOrMemberInfo> GetConstructorParameterBeanReferences(
            Type declaringBeanType, string constructorName
            , Diagnostics diagnostics
            )
        {
            WarnOfConstructorsWithMissingAttribute(declaringBeanType, diagnostics);
            List <ParamOrMemberInfo> @params = new List <ParamOrMemberInfo>();

            ValidateConstructors(declaringBeanType, constructorName, diagnostics);
            if (declaringBeanType.GetConstructors(constructorFlags).Length > 0)
            {
                var paramInfos = GetParametersForConstructorMatching(declaringBeanType, constructorName);
                if (paramInfos != null)
                {
                    foreach (var paramInfo in paramInfos)
                    {
                        var paramOrMemberInfo = new ParamOrMemberInfo(paramInfo);
                        if (ValidateMemberOrParameter(paramOrMemberInfo
                                                      , declaringBeanType, diagnostics))
                        {
                            yield return(paramOrMemberInfo);
//                            @params.Add(paramOrMemberInfo);
                        }
                    } // for each constructor parameter
                }
            }
//            return @params.AsReadOnly();
        } // CreateConstructorTrees()
Exemplo n.º 2
0
        // null return indicates this member is not a valid bean reference or constructor parameter
        private static bool ValidateMemberOrParameter(ParamOrMemberInfo paramOrMemberInfo
                                                      , Type declaringBeanType, Diagnostics diagnostics)
        {
            if (paramOrMemberInfo.IsBeanReference)
            {
                if (!paramOrMemberInfo.IsWriteable)
                {
                    RecordDiagnostic(diagnostics, "ReadOnlyProperty"
                                     , ("Class", declaringBeanType.GetSafeFullName())
                                     , ("Member", paramOrMemberInfo.Name));
                    return(false);
                }
                else // member is writable
                {
                    if (paramOrMemberInfo.IsFactory)
                    {
                        if (!typeof(IFactory).IsAssignableFrom(paramOrMemberInfo.Factory))
                        {
                            RecordDiagnostic(diagnostics, "BadFactory"
                                             , ("DeclaringBean", declaringBeanType.FullName)
                                             , ("Member", paramOrMemberInfo.Name)
                                             , ("Factory", paramOrMemberInfo.Factory.FullName)
                                             );
                            return(false);
                        }
                    }
                } // writeable member
                return(true);
            }     // this is a bean reference

            return(false);
        }
Exemplo n.º 3
0
        } // CreateConstructorTrees()

        public IEnumerable <ParamOrMemberInfo> GetMemberBeanReferences(
            Type declaringBeanType, Diagnostics diagnostics)
        {
            List <ParamOrMemberInfo> members = new List <ParamOrMemberInfo>();
            var fieldOrPropertyInfos         = declaringBeanType.GetMembers(constructorFlags)
                                               .Where(f => f is FieldInfo || f is PropertyInfo);

            foreach (var fieldOrPropertyInfo in fieldOrPropertyInfos)
            {
                var paramOrMemberInfo = new ParamOrMemberInfo(fieldOrPropertyInfo);
                if (ValidateMemberOrParameter(paramOrMemberInfo
                                              , declaringBeanType, diagnostics))
                {
//                    members.Add(paramOrMemberInfo);
                    yield return(paramOrMemberInfo);
                }
            } // for each property or field

//            return members.AsReadOnly();
        } // CreateMemberTrees()
Exemplo n.º 4
0