Creates instances from classes which are attributed by ConverterAttribute
More...
|
override object | Create (Type converterClass) |
| Creates a new instance of Type converterClass More...
|
|
override object | Create (Type converterClass, ConverterCollection collection=null) |
| Creates a new instance of Type converterClass 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...
|
|
Creates instances from classes which are attributed by ConverterAttribute
Definition at line 22 of file BaseClassFactoryRT.cs.
override object Core.TypeCast.Base.BaseClassFactoryRT.Create |
( |
Type |
converterClass | ) |
|
Creates a new instance of Type converterClass
- Parameters
-
- Exceptions
-
ConverterCollectionException | An exception raised by the Create method pre-instance creation, if the converterClass was previously instanced by the ConverterCollection. |
TargetInvocationException | An exception-wrapper containing an Exception.InnerException of an error which occurred during or at instance creation. |
Definition at line 32 of file BaseClassFactoryRT.cs.
34 return this.
Create(converterClass, ConverterCollection.CurrentInstance);
override object Create(Type converterClass)
Creates a new instance of Type converterClass
override object Core.TypeCast.Base.BaseClassFactoryRT.Create |
( |
Type |
converterClass, |
|
|
ConverterCollection |
collection = null |
|
) |
| |
Creates a new instance of Type converterClass
- Parameters
-
- Returns
- Returns a new instance of converterClass upon success, else null
- Exceptions
-
ConverterCollectionException | An exception raised by the Create method pre-instance creation, if the converterClass was previously instanced by the ConverterCollection. |
TargetInvocationException | An exception-wrapper containing an Exception.InnerException of an error which occurred during or at instance creation. |
Definition at line 47 of file BaseClassFactoryRT.cs.
49 if(collection?.ConverterClassInitialized.ContainsKey(converterClass.GetTypeInfo()) ==
true)
51 if(collection?.Settings.ConverterClassExistsException ==
true)
58 object customConverter;
61 if(typeof(ConverterCollectionDependency).GetTypeInfo().IsAssignableFrom(converterClass.GetTypeInfo())
62 || converterClass.GetTypeInfo().IsDependencyInjectable(typeof(IConverterCollection)))
64 customConverter =
Instantiate(type: converterClass, parameters: collection as IConverterCollection);
68 customConverter =
Instantiate(type: converterClass);
71 catch(TargetInvocationException exc)
73 throw exc?.InnerException;
76 return customConverter;
ConverterCollectionCause
Contains the reasons for a ConverterCollectionException to be raised.
static object Instantiate(Type type, params object[] parameters)
Internal method for object instantiation by a passed type type
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 |
|
) |
| |
|
staticprotectedinherited |
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: