コード例 #1
0
 /// <summary>
 /// Returns an instance of this <paramref name="type"/> using its two-parameter constructor
 /// and the given <paramref name="argument1"/> and <paramref name="argument2"/>.
 /// </summary>
 /// <typeparam name="TArg1">
 /// The type of the first argument to pass to the constructor.
 /// </typeparam>
 /// <typeparam name="TArg2">
 /// The type of the second argument to pass to the constructor.
 /// </typeparam>
 /// <param name="type">The type an instance of which to create.</param>
 /// <param name="argument1">The first argument to pass to the constructor.</param>
 /// <param name="argument2">The second argument to pass to the constructor.</param>
 /// <returns>An instance of this <paramref name="type"/>.</returns>
 public static object GetInstance <TArg1, TArg2>(
     this Type type,
     TArg1 argument1,
     TArg2 argument2)
 {
     return(InstanceFactoryCache <TArg1, TArg2> .GetFactoryFor(type)
            .Invoke(argument1, argument2));
 }
コード例 #2
0
 /// <summary>
 /// Returns an instance of this <paramref name="type"/> using its single-parameter constructor
 /// and the given <paramref name="argument"/>.
 /// </summary>
 /// <typeparam name="TArg">
 /// The type of the single argument to pass to the constructor.
 /// </typeparam>
 /// <param name="type">The type an instance of which to create.</param>
 /// <param name="argument">The single argument to pass to the constructor.</param>
 /// <returns>An instance of this <paramref name="type"/>.</returns>
 public static object GetInstance <TArg>(
     this Type type,
     TArg argument)
 {
     return(InstanceFactoryCache <TArg> .GetFactoryFor(type).Invoke(argument));
 }
コード例 #3
0
 /// <summary>
 /// Returns an instance of this <paramref name="type"/>.
 /// </summary>
 /// <param name="type">The type an instance of which to create.</param>
 /// <returns>An instance of this <paramref name="type"/>.</returns>
 public static Func <object> GetInstanceFactory(this Type type)
 => InstanceFactoryCache.GetFactoryFor(type);
コード例 #4
0
 /// <summary>
 /// Returns an instance of this <paramref name="type"/>.
 /// </summary>
 /// <param name="type">The type an instance of which to create.</param>
 /// <returns>An instance of this <paramref name="type"/>.</returns>
 public static object GetInstance(this Type type)
 => InstanceFactoryCache.GetFactoryFor(type).Invoke();