Example #1
0
        public R2 Provide(C2 context)
        {
            C1 c;

            if (!(context is C1) && context != null)
            {
                c = ConvertManager.ChangeType <C1>(context);
            }
            else
            {
                c = (C1)((object)context);
            }

            R1 res1 = UnderlyingProvider.Provide(c);
            R2 res2;

            if (!(res1 is R2) && res1 != null)
            {
                res2 = ConvertManager.ChangeType <R2>(res1);
            }
            else
            {
                res2 = (R2)((object)res1);
            }
            return(res2);
        }
Example #2
0
 public virtual object Convert(object o, Type toType)
 {
     if (TypeHelper.IsNullable(toType))
     {
         var underlyingToType = Nullable.GetUnderlyingType(toType);
         var underlyingValue  = ConvertManager.ChangeType(o, underlyingToType);
         return(Activator.CreateInstance(toType, underlyingValue));
     }
     throw new InvalidCastException();
 }
Example #3
0
        protected override object ConvertToGeneric(object o, Type toGenIType)
        {
            Type[]      collGArgs = toGenIType.GetGenericArguments();
            IEnumerable fromEnum  = (IEnumerable)o;

            var resList = new ArrayList();

            foreach (var elem in fromEnum)
            {
                resList.Add(ConvertManager.ChangeType(elem, collGArgs[0]));
            }
            return(resList.ToArray(collGArgs[0]));
        }
Example #4
0
        public void Execute(C2 context)
        {
            C1 c;

            if (!(context is C1) && context != null)
            {
                c = ConvertManager.ChangeType <C1>(context);
            }
            else
            {
                c = (C1)((object)context);
            }
            UnderlyingOperation.Execute(c);
        }
Example #5
0
 public virtual object Convert(object o, Type toType)
 {
     if (o is IEnumerable && toType.IsArray)
     {
         var elemType = toType.GetElementType();
         var enumList = (IEnumerable)o;
         var resList  = new ArrayList();
         foreach (var elem in enumList)
         {
             resList.Add(ConvertManager.ChangeType(elem, elemType));
         }
         return(resList.ToArray(elemType));
     }
     throw new InvalidCastException();
 }
Example #6
0
            protected override object Invoke(params object[] args)
            {
                var mParams = Method.GetParameters();

                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] != null)
                    {
                        if (mParams.Length > i && !mParams[i].ParameterType.IsAssignableFrom(args[i].GetType()))
                        {
                            args[i] = ConvertManager.ChangeType(args[i], mParams[i].ParameterType);
                        }
                    }
                }
                return(Method.Invoke(Target, args));
            }
Example #7
0
            public override IMessage Invoke(IMessage m)
            {
                if (m is IMethodCallMessage)
                {
                    var methodCall = (IMethodCallMessage)m;

                    var args = (object[])methodCall.Args.Clone();
                    // check args contravariance
                    var mParams = Method.GetParameters();
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] != null)
                        {
                            if (mParams.Length > i && !mParams[i].ParameterType.IsAssignableFrom(args[i].GetType()))
                            {
                                try {
                                    args[i] = ConvertManager.ChangeType(args[i], mParams[i].ParameterType);
                                } catch (Exception ex) {
                                    throw new InvalidCastException(
                                              String.Format("Cannot convert parameter #{0} for {1}.{2} -> {3}.{4}: {5}",
                                                            i, InterfaceType.ToString(), InterfaceMethod.Name,
                                                            Method.DeclaringType.ToString(), Method.Name,
                                                            ex.Message), ex);
                                }
                            }
                        }
                    }
                    var response = Method.Invoke(Target, args);
                    if (response != null && InterfaceMethod.ReturnType != typeof(void) && !InterfaceMethod.ReturnType.IsAssignableFrom(response.GetType()))
                    {
                        try {
                            response = ConvertManager.ChangeType(response, InterfaceMethod.ReturnType);
                        } catch (Exception ex) {
                            throw new InvalidCastException(
                                      String.Format("Cannot convert result for {0}.{1} -> {2}.{3}: {2}",
                                                    InterfaceType.ToString(), InterfaceMethod.Name,
                                                    Method.DeclaringType.ToString(), Method.Name,
                                                    ex.Message), ex);
                        }
                    }
                    return(new ReturnMessage(response, null, 0, null, methodCall));
                }
                throw new NotImplementedException();
            }
Example #8
0
 public T Invoke <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, T>(P1 arg1, P2 arg2, P3 arg3, P4 arg4, P5 arg5, P6 arg6, P7 arg7, P8 arg8, P9 arg9, P10 arg10, P11 arg11, P12 arg12, P13 arg13, P14 arg14)
 {
     return((T)ConvertManager.ChangeType(Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14), typeof(T)));
 }
Example #9
0
 public T Invoke <P1, P2, P3, P4, P5, P6, P7, P8, T>(P1 arg1, P2 arg2, P3 arg3, P4 arg4, P5 arg5, P6 arg6, P7 arg7, P8 arg8)
 {
     return((T)ConvertManager.ChangeType(Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), typeof(T)));
 }
Example #10
0
 public T Invoke <P1, P2, P3, P4, P5, T>(P1 arg1, P2 arg2, P3 arg3, P4 arg4, P5 arg5)
 {
     return((T)ConvertManager.ChangeType(Invoke(arg1, arg2, arg3, arg4, arg5), typeof(T)));
 }
Example #11
0
 public T Invoke <P1, P2, P3, T>(P1 arg1, P2 arg2, P3 arg3)
 {
     return((T)ConvertManager.ChangeType(Invoke(arg1, arg2, arg3), typeof(T)));
 }
Example #12
0
 public T Invoke <P1, T>(P1 arg1)
 {
     return((T)ConvertManager.ChangeType(Invoke(arg1), typeof(T)));
 }
Example #13
0
 public T Invoke <T>()
 {
     return((T)ConvertManager.ChangeType(Invoke(), typeof(T)));
 }