示例#1
0
        public static ServiceClass GetClassFromType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return(JsonRpcServiceReflector.FromType(type));
        }
示例#2
0
        void IServiceClassReflector.Build(ServiceClassBuilder builder)
        {
            if (_type == null)
            {
                throw new InvalidOperationException();
            }

            builder.Name = Name;

            //
            // Get all the public instance methods on the type and create a
            // filtered table of those to expose from the service.
            //

            MethodInfo[] publicMethods = _type.GetMethods(BindingFlags.Public | BindingFlags.Instance);

            foreach (MethodInfo method in publicMethods)
            {
                if (JsonRpcServiceReflector.ShouldBuild(method))
                {
                    JsonRpcServiceReflector.BuildMethod(builder.DefineMethod(), method);
                }
            }
        }
示例#3
0
        void IMethodReflector.Build(MethodBuilder builder)
        {
            if (_method == null)
            {
                throw new InvalidOperationException();
            }

            builder.Name       = Name;
            builder.Idempotent = Idempotent;

            //
            // Build the method parameters.
            //

            MethodInfo method = _method;

            ParameterInfo[] parameters = method.GetParameters();

            if (method.IsStatic)
            {
                ParameterInfo[] logicalParameters = new ParameterInfo[parameters.Length - 1];
                Array.Copy(parameters, 1, logicalParameters, 0, logicalParameters.Length);
                parameters = logicalParameters;
            }

            if (WarpedParameters)
            {
                if (parameters.Length != 1)
                {
                    // TODO: Use a more specific exception type
                    throw new Exception(string.Format(
                                            "Methods using warped parameters must accept a single argument of the warped type whereas method {1} on {0} accepts {2}.",
                                            method.DeclaringType.FullName, method.Name, parameters.Length.ToString()));
                }

                PropertyDescriptorCollection args = GetProperties(parameters[0].ParameterType);
                foreach (PropertyDescriptor arg in args)
                {
                    ParameterBuilder parameter = builder.DefineParameter();
                    parameter.Name          = arg.Name;
                    parameter.ParameterType = arg.PropertyType;
                }

                PropertyDescriptor result = null;

                if (method.ReturnType != typeof(void))
                {
                    PropertyDescriptorCollection results = GetProperties(method.ReturnType);
                    if (results.Count > 0)
                    {
                        result             = results[0];
                        builder.ResultType = result.PropertyType;
                    }
                }

                builder.Handler = new WarpedMethodImpl(builder.Handler,
                                                       parameters[0].ParameterType,
                                                       args, result);
            }
            else
            {
                foreach (ParameterInfo parameter in parameters)
                {
                    JsonRpcServiceReflector.BuildParameter(builder.DefineParameter(), parameter);
                }
            }
        }