private static void BuildMethod(MethodBuilder builder, MethodInfo method) { Debug.Assert(method != null); Debug.Assert(builder != null); builder.InternalName = method.Name; builder.ResultType = method.ReturnType; builder.Handler = new TypeMethodImpl(method); // // Build via attributes. // object[] attributes = method.GetCustomAttributes(typeof(Attribute), true); foreach (Attribute attribute in attributes) { IMethodReflector reflector = attribute as IMethodReflector; if (reflector != null) reflector.Build(builder, method); else builder.AddCustomAttribute(attribute); } // // Fault in the method name if still without name. // if (builder.Name.Length == 0) builder.Name = method.Name; // // Build the method parameters. // foreach (ParameterInfo parameter in method.GetParameters()) BuildParameter(builder.DefineParameter(), parameter); }
public void Init() { _methodBuilder = (new ServiceClassBuilder()).DefineMethod(); _builder = _methodBuilder.DefineParameter(); }
void IMethodReflector.Build(MethodBuilder builder, MethodInfo method) { builder.Name = Name; builder.Idempotent = Idempotent; // // Build the method parameters. // ParameterInfo[] parameters = method.GetParameters(); if (WarpedParameters) { if (parameters.Length != 1) { // TODO: Use a more specific exception type throw new Exception(string.Format( "Methods used warped parameters must accept a single argument of the warped type only 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); } }