/// <summary> /// Gets a mapping of method JsonName to MethodInfo for a given type. /// </summary> /// <param name="serviceType"></param> /// <returns></returns> private static Dictionary <String, MethodInfo> CreateMethodMap(Type serviceType) { Dictionary <string, MethodInfo> methodMap = new Dictionary <String, MethodInfo>(); // load methods into method map foreach (MethodInfo info in serviceType.GetMethods()) { if (!info.IsPublic) { continue; } if (!JsonMethodAttribute.IsJsonMethod(info)) { continue; } string jsonName = JsonMethodAttribute.GetJsonName(info); if (String.IsNullOrEmpty(jsonName)) { methodMap[info.Name] = info; } else { methodMap[jsonName] = info; } } return(methodMap); }
/// <summary> /// Ctor. /// </summary> internal JsonMethodDescription(MethodInfo method) { //TODO: clean up JsonMethodDescription efficiency if (method == null) { return; } if (!JsonMethodAttribute.IsJsonMethod(method)) { throw new InvalidMethodException("Specified method is not marked as a JsonMethod."); } this.Name = JsonMethodAttribute.GetJsonName(method); if (String.IsNullOrEmpty(this.Name)) { this.name = method.Name; } ParameterInfo[] parameters = method.GetParameters(); this.Params = new JsonNamedParameterDescription[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { this.Params[i] = new JsonNamedParameterDescription(parameters[i]); } this.Return = new JsonParameterDescription(method.ReturnParameter); this.Help = JsonMethodAttribute.GetHelpUrl(method); this.Idempotent = JsonMethodAttribute.IsIdempotent(method); if (Attribute.IsDefined(method, typeof(DescriptionAttribute))) { DescriptionAttribute description = Attribute.GetCustomAttribute(method, typeof(DescriptionAttribute), true) as DescriptionAttribute; this.Summary = description.Description; } }