/// <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 JsonServiceDescription(Type serviceType, string serviceUrl) { //TODO: clean up JsonServiceDescription efficiency if (serviceType == null) { return; } if (!JsonServiceAttribute.IsJsonService(serviceType)) { throw new InvalidRequestException("Specified type is not marked as a JsonService."); } this.Namespace = JsonServiceAttribute.GetNamespace(serviceType); if (String.IsNullOrEmpty(this.Namespace)) { this.name = serviceType.Namespace; } this.Name = JsonNameAttribute.GetJsonName(serviceType); if (String.IsNullOrEmpty(this.Name)) { this.name = serviceType.Name; } MethodInfo[] infos = serviceType.GetMethods(); List <JsonMethodDescription> methods = new List <JsonMethodDescription>(infos.Length); foreach (MethodInfo info in infos) { if (info.IsPublic && JsonMethodAttribute.IsJsonMethod(info)) { methods.Add(new JsonMethodDescription(info)); } } this.Methods = methods.ToArray(); this.ID = "urn:uuid:" + serviceType.GUID; Version assemblyVersion = serviceType.Assembly.GetName().Version; this.Version = assemblyVersion.ToString(2); this.Address = serviceUrl; this.Help = JsonServiceAttribute.GetHelpUrl(serviceType); if (Attribute.IsDefined(serviceType, typeof(DescriptionAttribute))) { DescriptionAttribute description = Attribute.GetCustomAttribute(serviceType, typeof(DescriptionAttribute), true) as DescriptionAttribute; this.Summary = description.Description; } }
/// <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; } }