The abstract generic factory for creating arbitrary instances requiring up to two arguments. Use a container type such as Tuple or struct as second parameter type TIn2 if more parameters are required.
More...
|
IEnumerable< Type > | GetInterfaces () |
| Returns an IEnumerable<Type> of the interfaces supported by the factory instance. More...
|
|
IEnumerable< Type > | GetParameters () |
| Returns an IEnumerable<Type> of the generic parameters that constructed the base-factory instance. More...
|
|
abstract TInstance | Create (TIn1 parameter) |
| Abstract method for creating instances of TInstance defined only through parameter More...
|
|
abstract TInstance | Create (TIn1 parameter, TIn2 parameter2=default(TIn2)) |
| Abstract method for creating instances of TInstance defined only through parameter and parameter2 More...
|
|
override string | ToString () |
| Returns a string representation of the Factory type. More...
|
|
|
static object | Instantiate (Type type, params object[] parameters) |
| Internal method for object instantiation by a passed type type More...
|
|
static bool | TryInstantiate (Type type, out object instance, params object[] parameters) |
| Internal method for object instantiation following the "Try" convention of returning a bool true upon success and passing the result with out More...
|
|
static TOut | Instantiate< TOut > (Type type, Type[] parameters, params object[] args) |
| Internal method object instantiation of a generic type , with the generic-parameters passed as the second argument More...
|
|
static TOut | Instantiate< TOut > (Type type, object[] args=null) |
| Creates an instance of the type designated by the specified generic type parameter More...
|
|
The abstract generic factory for creating arbitrary instances requiring up to two arguments. Use a container type such as Tuple or struct as second parameter type TIn2 if more parameters are required.
- Template Parameters
-
Definition at line 30 of file Factory.cs.
Abstract method for creating instances of TInstance defined only through parameter
- Parameters
-
parameter | The parameter to define the instance creation process |
- Returns
- an instance of Type TInstance
Abstract method for creating instances of TInstance defined only through parameter and parameter2
- Parameters
-
parameter | The parameter to define the instance creation process |
parameter2 | The 2. parameter to define the instance creation process |
- Returns
- an instance of Type TInstance
Returns an IEnumerable<Type> of the interfaces supported by the factory instance.
Definition at line 46 of file Factory.cs.
48 var type = this.GetType();
51 foreach(var interfaceType
in type.GetTypeInfo().ImplementedInterfaces)
53 yield
return interfaceType;
Returns an IEnumerable<Type> of the generic parameters that constructed the base-factory instance.
Definition at line 60 of file Factory.cs.
62 var type = this.GetType();
65 foreach(var parameterType
in type.GetTypeInfo().GenericTypeParameters)
67 yield
return parameterType;
Internal method for object instantiation by a passed type type
- Parameters
-
type | the type of the class or struct which to instance |
parameters | the parameters passed to the constructor of the class or struct |
- Returns
- Returns an instance object of type TOut or
null
Definition at line 93 of file Factory.cs.
95 return Instantiate<object>(type: type, args: parameters);
Internal method object instantiation of a generic type , with the generic-parameters passed as the second argument
- Template Parameters
-
TOut | The type of the instance to pass out |
- Parameters
-
type | The type of the class or struct which to instance |
parameters | the generic types that comprise the generic type |
args | The parameters passed to the constructor of the class or struct |
- Returns
- Returns an instance object of type TOut or
null
Definition at line 125 of file Factory.cs.
127 var constructed = type.GetTypeInfo().MakeGenericType(parameters);
static TOut Instantiate< TOut >(Type type, Type[] parameters, params object[] args)
Internal method object instantiation of a generic type , with the generic-parameters passed as the se...
Creates an instance of the type designated by the specified generic type parameter
- Parameters
-
type | The type of the class or struct which to instance |
args | the parameters passed to the constructor of the class or struct |
- Returns
- A reference to the newly created object.
- Exceptions
-
System.MissingMethodException | NoteIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, System.MissingMemberException, instead. The type that specified for T does not have a parameterless constructor. |
Centralize all runtime calls to
<tt>Activator.Create(...)</tt>
and
Definition at line 141 of file Factory.cs.
143 if(args?.Length == 0)
145 return (TOut)Activator.CreateInstance(type);
147 return (TOut)Activator.CreateInstance(type, args);
Returns a string representation of the Factory type.
Definition at line 153 of file Factory.cs.
155 var type = this.GetType().GetTypeInfo();
156 var genericArgs = type.GenericTypeArguments;
157 if(genericArgs.Any())
159 var typeNames = genericArgs.Select(t => t.Name)
160 .Aggregate((a, b) => a +
',' + b);
161 return $
"{type.Name} <{typeNames}>";
static bool Core.TypeCast.Base.Factory< TInstance, TIn1, TIn2 >.TryInstantiate |
( |
Type |
type, |
|
|
out object |
instance, |
|
|
params object[] |
parameters |
|
) |
| |
|
staticprotected |
Internal method for object instantiation following the "Try" convention of returning a bool true
upon success and passing the result with out
- Parameters
-
type | The type of the class or struct which to instance |
parameters | The parameters passed to the constructor of the class or struct |
instance | The assigned instance reference upon instancing of type TOut or null upon failure |
- Returns
- Returns bool
true
upon success or false
upon failure and assigning null
to instance
Definition at line 105 of file Factory.cs.
109 instance = Instantiate<object>(type: type, args: parameters);
The documentation for this class was generated from the following file: