9 namespace Core.TypeCast.Base
15 using System.Reflection;
16 using System.Runtime.Serialization;
21 [System.Runtime.InteropServices.ComVisible(
false)]
32 public override Converter Create<TIn, TOut>(Func<TIn, TOut> method)
35 converter.MergeFromMethodAttribute(method.GetMethodInfo());
48 public override Converter Create<TIn, TOut>(Func<TIn, TOut, TOut> method)
51 converter.MergeFromMethodAttribute(method.GetMethodInfo());
65 MethodInfo makeConverter;
66 if(declaredMethod.GetParameters().Length == 0)
70 .MakeGenericMethod(type.AsType(), declaredMethod.ReturnParameter.ParameterType);
72 else if(declaredMethod.GetParameters().Length == 1)
76 .MakeGenericMethod(type.AsType(), declaredMethod.GetParameters().FirstOrDefault().ParameterType, declaredMethod.ReturnParameter.ParameterType);
82 var args =
new object[] { declaredMethod };
84 var converter = (
Converter)makeConverter.Invoke(
this, args);
86 converter.MergeFromMethodAttribute(declaredMethod);
98 public Converter ConverterWrapper<TClass, TOut>(MethodInfo declaredMethod)
100 return this.Create<TClass, TOut>(InvocationWrapper<TClass, TOut>(declaredMethod));
112 public static Converter ConverterWrapperAny<TClass, TArg, TOut>(MethodInfo declaredMethod)
124 private static Func<TClass, TOut> InvocationWrapper<TClass, TOut>(MethodInfo declaredMethod)
126 return (instance) => (TOut)declaredMethod.Invoke(instance, null);
138 private static Func<TClass, TArg, TOut> InvocationWrapper<TClass, TArg, TOut>(MethodInfo declaredMethod)
140 return (instance, parameter) => (TOut)declaredMethod.Invoke(instance,
new object[] { parameter });
Converter CreateWrapper(TypeInfo type, MethodInfo declaredMethod)
Create a converter-wrapper which passes the own class-instance of a given method declaredMethod as f...
The Exception-type which is raised exclusively by the Converter<TIn,TOut> Library ...
Creates new instances of Converter<TIn, TOut> dependent on the source TIn and target Type TOut ...
ConverterCause
Contains the reasons for a ConverterException to be raised.
The Converter base class, providing a simple container for conversion types, ConverterAttribute and c...