public object Create(ConstructionParameters parameters) { if (parameters == null) { parameters = ConstructionParameters.Empty; } Func <object[], object> method; var values = new object[parameters.ParameterCount]; var key = new StringBuilder(); for (int i = 0; i < parameters.ParameterCount; i++) { key.Append(parameters.ParameterTypes[i].ToString()); values[i] = parameters.ParameterValues[i](); } if (!constructors.TryGetValue(key.ToString(), out method)) { if (parameters.ParameterCount > 0) { throw new ArgumentException("Constructor for type '" + originalType + "' with argument types '" + string.Join(", ", parameters.ParameterTypes.AsEnumerable()) + "' could not be found."); } else { throw new ArgumentException("Constructor for type '" + originalType + "' with no arguments could not be found."); } } return(method(values)); }
/// <summary> /// Creates a customized proxy instance of the requested type. /// </summary> /// <param name="type">The type to create proxy for.</param> /// <param name="parameters">The construction parameters.</param> /// <param name="initialize">If set to <c>true</c>, the instance should be initialized using the registered initializers.</param> /// <returns>Returns a new proxy instance.</returns> public object CreateInstance(Type type, ConstructionParameters parameters = null, bool initialize = true) { var instance = generator.CreateInstance(type, parameters); if (initialize) { InitializeInstance(type, instance); } return(instance); }
/// <summary> /// Creates a customized proxy instance of the requested type. /// </summary> /// <typeparam name="T">The type to create proxy for.</typeparam> /// <param name="parameters">The construction parameters.</param> /// <param name="initialize">If set to <c>true</c>, the instance should be initialized using the registered initializers.</param> /// <returns>Returns a new proxy instance.</returns> public T CreateInstance <T>(ConstructionParameters parameters = null, bool initialize = true) { return((T)CreateInstance(typeof(T), parameters, initialize)); }
public object CreateInstance(Type type, ConstructionParameters parameters) { return(factories.GetOrAdd(type, CreateFactory).Create(parameters)); }