public void FetchClassDocumentation() { if (_apiDescriptor.Documentation != null) return; var attrs = _apiDescriptor.ApiType.GetCustomAttributes(typeof(DocumentationAttribute), true); if (attrs.Length == 0) return; foreach (DocumentationAttribute attr in attrs) { string path = attr.Path; if (!File.Exists(path)) { path = HttpContext.Current.Server.MapPath(path); if (!File.Exists(path)) throw new FileNotFoundException("没有找到说明文档"); } var provider = new XmlDocumentationProvider(path); provider.SetDocumentation(_apiDescriptor, true); } }
public bool EnableDocumentation() { if (_documentaionEnabled) return true; lock (_syncRoot) { if (_documentaionEnabled) return true; bool enable = false; var attrs = _apiDescriptor.ApiType.GetCustomAttributes(typeof(DocumentationAttribute), true); if (attrs.Length > 0) { using (var fs = typeof(ApiManager).Assembly.GetManifestResourceStream(ResManager.GetResourceId("Cus.WebApi.XML"))) { var selfProvider = new XmlDocumentationProvider(fs); selfProvider.SetDocumentation(_apiDescriptor); } foreach (DocumentationAttribute attr in attrs) { string path = attr.Path; if (!File.Exists(path)) { path = HttpContext.Current.Server.MapPath(path); if (!File.Exists(path)) throw new FileNotFoundException("没有找到说明文档"); } var provider = new XmlDocumentationProvider(path); provider.SetDocumentation(_apiDescriptor); enable = true; } foreach (var method in _apiDescriptor.Methods) { PropertyDescriptor result; if (!method.ResponseParam.PropertiesDic.TryGetValue("result", out result)) continue; result.Documentation = method.ResponseParam.Documentation; } } _documentaionEnabled = enable; return _documentaionEnabled; } }