Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static object CreateInstance(Type objectType, params object[] parameters)
        {
            IDynamicConstructor ctor = DynamicConstructorCache.GetDynamicConstructor(objectType, parameters);

            if (ctor == null)
            {
                ThrowHelper.ThrowNotImplementedException(ReflectionSR.ConstructorNotImplemented, objectType.FullName, TypeHelper.GetTypesString(parameters));
            }

            return(ctor.Invoke(parameters));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses reflection to create an object using its
        /// default constructor.
        /// </summary>
        /// <param name="objectType">Type of object to create.</param>
        public static object CreateInstance(Type objectType)
        {
            IDynamicConstructor ctor = DynamicConstructorCache.GetDynamicConstructor(objectType, Type.EmptyTypes);

            if (ctor == null)
            {
                ThrowHelper.ThrowNotImplementedException(ReflectionSR.DefaultConstructorMethodNotImplemented, objectType.FullName);
            }

            return(ctor.Invoke(null));
        }
Ejemplo n.º 3
0
        public static object CreateInstance(Type objectType, IDictionary <string, object> namedArgValues)
        {
            object target            = null;
            IDynamicConstructor ctor = DynamicConstructorCache.GetDynamicConstructor(objectType, namedArgValues);

            if (ctor != null)
            {
                target = ctor.Invoke(namedArgValues.Values.ToArray());
            }

            return(target);
        }