Example #1
0
        public ObjectConstructor(Type type, ConstructorInfo[] ctors)
        {
            if (type == null) throw new ArgumentNullException("type");

            if (ctors == null)
            {
                ctors = type.GetConstructors();
            }
            else
            {
                foreach (ConstructorInfo ctor in ctors)
                {
                    if (ctor.DeclaringType != type)
                        throw new ArgumentException(null, "ctors");
                }

                ctors = (ConstructorInfo[]) ctors.Clone();
            }

            if (type.IsClass && ctors.Length == 0)
            {
                //
                // Value types are excluded here because they always have
                // a default constructor available but one which does not
                // show up in reflection.
                //

                throw new ArgumentException(null, "ctors");
            }

            _type = type;
            _ctors = ctors;
            Array.Sort(_ctors, _arrayLengthComparer);
        }