コード例 #1
0
        // ---------------------------
        // ---------------------------
        // ---------------------------
        // ---------------------------

        #region analysis logic
        /// <summary>
        /// Returns Value=null if this type does not apply.
        /// </summary>
        static Contains <ParametricConstructorDescriptor> AnalyseClassType(Type t)
        {
            if (!TypeEx.IsEnum(t) && !_InvalidatedTypes.Contains(t))
            {
                bool AvoidDefaultConstructor = true;                 // Never uses a default constructor.

                BindingFlags[] bflags = new BindingFlags[2] {
                    BindingFlags.Public | BindingFlags.Instance, BindingFlags.NonPublic | BindingFlags.Instance
                };

                // 2 passes: one with public constructors, and one with private constructors.
                for (int iflags = 0; iflags < 2; iflags++)
                {
                    var             cs = t.GetConstructors(bflags[iflags]).Where((ci) => AvoidDefaultConstructor ? ci.GetParameters().Length != 0 : true);
                    ConstructorInfo cons;
                    var             mf = AnalyseConstructors(cs, out cons);
                    if (mf != null)
                    {
                        return(ParametricConstructorDescriptor.CreateDirectTypeParamDescriptor(cons, mf.ToArray()));
                    }
                }
            }

            return(new Contains <ParametricConstructorDescriptor>(null));           // This type does not apply.
        }
コード例 #2
0
        internal static object[] GetParameterFields(object o, ParametricConstructorDescriptor d)
        {
            var cons       = d.constructorInfo;
            var fields     = d.ParameterFields;
            var parameters = cons.GetParameters();

            object[] ret = new object[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                var field = fields[i];
                ret[i] = field.GetValue(o);
            }

            return(ret);
        }