Creates new instances of Converter<TIn, TOut> or Converter<TIn, TOut, TArg> dependent on the number of parameters defined in methodInfo and whether a delegate was passed.
More...
|
override Converter | Create (MethodInfo method) |
|
override Converter | Create (MethodInfo methodInfo, object converterDelegate=null) |
| Creates a strictly typed Converter<TIn, TOut, TArg> container in case of any attribute-assigned method or a passed MethodInfo with a parameter argument count of two. Otherwise a strictly typed Converter<TIn, TOut> container instance is created and returned. 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 new instances of Converter<TIn, TOut> or Converter<TIn, TOut, TArg> dependent on the number of parameters defined in methodInfo and whether a delegate was passed.
- Template Parameters
-
TConverter | The generic type of the Converter class to instance |
Definition at line 22 of file ConverterFactoryRT.cs.
Creates a strictly typed Converter<TIn, TOut, TArg> container in case of any attribute-assigned method or a passed MethodInfo with a parameter argument count of two. Otherwise a strictly typed Converter<TIn, TOut> container instance is created and returned.
- Parameters
-
methodInfo | A methodInfo for a converter method, crucially confining the number of function parameters between one and two. Otherwise an ConverterException is raised. |
converterDelegate | An optional delegate of the converter method. |
- Returns
- A new instance of a Converter with a parent of either Converter<TIn, TOut, TArg> or Converter<TIn, TOut>.
- Exceptions
-
ConverterException | If the number or types of the parameters mismatch an exception is raised. |
Definition at line 39 of file ConverterFactoryRT.cs.
41 if(methodInfo == null && converterDelegate == null)
43 throw new ConverterException(
ConverterCause.ConverterArgumentNull);
46 var parameterInfos = methodInfo.GetParameters();
48 if(parameterInfos.Length == 0)
50 throw new ConverterException(
ConverterCause.ConverterArgumentDelegateNoParameters);
53 bool isInstanceMethod = converterDelegate == null;
55 var parameterTypes =
new ConverterParameters(methodInfo.ReturnParameter, parameterInfos);
59 var methodAttribute = methodInfo.GetCustomAttribute<ConverterMethodAttribute>();
62 if(parameterInfos.Length == 2 || isInstanceMethod ==
true)
64 converter = Instantiate<Converter>(typeof(Converter<,,>), parameters: parameterTypes.ToArray(), args:
new[] { converterDelegate ?? methodInfo, parameterTypes.Arg });
66 converter.FunctionDefaultAttribute = methodAttribute;
67 converter.FunctionAttribute = methodAttribute;
69 else if(parameterInfos.Length == 1)
71 converter = Instantiate<Converter>(typeof(Converter<,>), parameters:
new[] { parameterTypes.In, parameterTypes.Out }, args: converterDelegate);
72 converter.FunctionAttribute = methodAttribute;
76 throw new ConverterException(
ConverterCause.ConverterArgumentDelegateTooManyParameters);
79 converter.MergeFromMethodAttribute(methodInfo);
ConverterCause
Contains the reasons for a ConverterException to be raised.
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: