/// <summary> /// 为Controller设置注释 /// </summary> /// <param name="controller"></param> private static void SetControllerNote(ControllerModel controller) { #region 设置Controller注释 string baseDir = AppDomain.CurrentDomain.BaseDirectory; DirectoryInfo dirInfo = new DirectoryInfo(baseDir); string xmlNoteFileName = controller.ModuleName.Replace(".dll", ".xml"); FileInfo fileInfo = dirInfo.GetFiles(xmlNoteFileName, SearchOption.AllDirectories).FirstOrDefault(); if (fileInfo != null) { AssemblyNoteModel noteModel = AssemblyHelper.GetAssemblyNote(fileInfo.FullName); if (noteModel != null) { //Controller 注释 controller.NoteModel = noteModel.MemberList.FirstOrDefault(member => member.Name == controller.Id); foreach (ActionModel action in controller.ActionList) { //Action注释 action.NoteModel = noteModel.MemberList.FirstOrDefault(member => member.Name == action.Id); if (action.NoteModel != null) { foreach (ParamModel param in action.InputParameters) { //输入参数注释 if (action.NoteModel.ParamList.Keys.Contains(param.Name)) { param.Summary = action.NoteModel.ParamList[param.Name]; } } //返回参数注释 action.ReturnParameter.Summary = action.NoteModel.Returns; } } } } #endregion }
/// <summary> /// 获取AssemblyNote /// </summary> /// <param name="xmlFilePath">xml文件路径</param> /// <returns></returns> public static AssemblyNoteModel GetAssemblyNote(string xmlFilePath) { FileInfo fileInfo = new FileInfo(xmlFilePath); if (!File.Exists(xmlFilePath)) { return(null); } XmlHelper xmlHelper = new XmlHelper(xmlFilePath); AssemblyNoteModel assemblyNoteModel = xmlHelper.DeserializeNode <AssemblyNoteModel>("assembly"); assemblyNoteModel.ModuleName = fileInfo.Name.Replace(".xml", ".dll"); XmlNode memberListNode = xmlHelper.GetNode("members"); XmlNode memberNode = memberListNode.FirstChild; while (memberNode != null) { MemberNoteModel memberModel = GetMember(memberNode); assemblyNoteModel.MemberList.Add(memberModel); memberNode = memberNode.NextSibling; } return(assemblyNoteModel); }
/// <summary> /// 初始化AllControllerNote /// </summary> private static void InitAllControllerNote() { List <AssemblyNoteModel> noteList = new List <AssemblyNoteModel>(); #region 处理AssemblyNote List <string> moduleList = controllerList.Select(controller => controller.ModuleName).Distinct().ToList(); string baseDir = AppDomain.CurrentDomain.BaseDirectory; DirectoryInfo dirInfo = new DirectoryInfo(baseDir); for (int i = 0; i < moduleList.Count; i++) { string xmlNoteFileName = moduleList[i].Replace(".dll", ".xml"); FileInfo fileInfo = dirInfo.GetFiles(xmlNoteFileName, SearchOption.AllDirectories).FirstOrDefault(); if (fileInfo != null) { AssemblyNoteModel noteModel = AssemblyHelper.GetAssemblyNote(fileInfo.FullName); noteList.Add(noteModel); } } #endregion for (int i = 0; i < controllerList.Count; i++) { ControllerModel controller = controllerList[i]; AssemblyNoteModel noteModel = noteList.FirstOrDefault(note => note.ModuleName == controller.ModuleName); if (noteModel == null) { continue; } //Controller 注释 controller.NoteModel = noteModel.MemberList.FirstOrDefault(member => member.Name == controller.Id); foreach (ActionModel action in controller.ActionList) { //Action注释 action.NoteModel = noteModel.MemberList.FirstOrDefault(member => member.Name == action.Id); if (action.NoteModel != null) { foreach (ParamModel param in action.InputParameters) { //输入参数注释 if (action.NoteModel.ParamList.Keys.Contains(param.Name)) { param.Summary = action.NoteModel.ParamList[param.Name]; } } //返回参数注释 action.ReturnParameter.Summary = action.NoteModel.Returns; } } } }
/// <summary> /// 为ptype设置注释 /// </summary> /// <param name="ptype"></param> private static void SetPTypeNote(PTypeModel ptype) { #region 设置PType注释 string baseDir = AppDomain.CurrentDomain.BaseDirectory; DirectoryInfo dirInfo = new DirectoryInfo(baseDir); string xmlNoteFileName = ptype.ModuleName.Replace(".dll", ".xml"); FileInfo fileInfo = dirInfo.GetFiles(xmlNoteFileName, SearchOption.AllDirectories).FirstOrDefault(); if (fileInfo != null) { AssemblyNoteModel noteModel = AssemblyHelper.GetAssemblyNote(fileInfo.FullName); if (noteModel != null) { //Controller 注释 ptype.Summary = noteModel.MemberList.FirstOrDefault(member => member.Name == ptype.Id)?.Summary; foreach (ParamModel param in ptype.PiList) { param.Summary = noteModel.MemberList.FirstOrDefault(member => member.Name == param.Id)?.Summary; } } } #endregion }