Ejemplo n.º 1
0
        private object[] ConvertParameters(string methodName, List <object> args, List <int> callbacks, List <ParameterInfo> paramInfo)
        {
            object[] parameters = new object[paramInfo.Count];

            // Special handling for the first parameter if it's of type Connection.
            if (paramInfo.Count > 0 && paramInfo[0].ParameterType.Equals(typeof(Connection)))
            {
                parameters[0] = this;
                var otherParams = ConvertParameters(methodName, args, callbacks, paramInfo.GetRange(1, paramInfo.Count - 1));
                otherParams.CopyTo(parameters, 1);
                return(parameters);
            }

            if (paramInfo.Count != args.Count)
            {
                throw new Exception("Incorrect number of arguments for a method. Expected: " +
                                    paramInfo.Count + ". Received: " + args.Count);
            }

            for (int i = 0; i < args.Count; i++)
            {
                // TODO: Handling of callbacks will change in the future and callbacks should be derived from the IDL.
                // Callbacks should not be transmitted as extra list, as it is unclear how list is treated in some protocols
                if (callbacks != null && callbacks.Contains(i))
                {
                    if (paramInfo[i].ParameterType == typeof(ClientFunction))
                    {
                        parameters[i] = CreateFuncWrapperDelegate((string)args[i]);
                    }
                    else if (typeof(Delegate).IsAssignableFrom(paramInfo[i].ParameterType))
                    {
                        parameters[i] = CreateCustomDelegate((string)args[i], paramInfo[i].ParameterType);
                    }
                    else
                    {
                        throw new Exception("Parameter " + i + " is neither a delegate nor a FuncWrapper. " +
                                            "Cannot pass callback method in its place");
                    }
                }
                else
                {
                    // Super Evil Hack! See other super evil hack comment above
                    if (SinTD == null)
                    {
                        parameters[i] = Convert.ChangeType(args[i], paramInfo[i].ParameterType);
                    }
                    else
                    {
                        string[]  service      = methodName.Split('.');
                        SinTDType idlParameter = SinTD.SINFONIServices.GetService(service[0])
                                                 .GetServiceFunction(service[1]).Parameters.ElementAt(i).Value;
                        parameters[i] = idlParameter.AssignValuesToNativeType(args[i], paramInfo[i].ParameterType);
                    }
                }
            }

            return(parameters);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the <paramref name="result"/> into <paramref name="type"/>.
        /// </summary>
        /// <returns>The converted result.</returns>
        /// <param name="result">Result.</param>
        /// <param name="type">Type to which the result must be converted.</param>
        protected object ConvertResult(object result, Type type)
        {
            SinTDType idlReturnType = CallingConnection.SinTD.SINFONIServices
                                      .GetService(ServiceName)
                                      .GetServiceFunction(FunctionName)
                                      .ReturnType;

            var convertedResult = idlReturnType.AssignValuesToNativeType(result, type);

            return(convertedResult);
        }