/// <summary> /// 包含List /// </summary> /// <param name="type"></param> /// <param name="content"></param> /// <param name="s"></param> /// <returns></returns> private static string CreateFieldList(int type, string content, AnalysisVo s) { content += " private " + "List<" + "" + s.Type + "> _" + s.Name + " = new List<" + s.Type + ">()" + ";" + "\r\n"; content += " /// <summary>\r\n"; content += " /// " + s.Note + "\r\n"; content += " /// </summary>\r\n"; content += " public " + "List<" + "" + s.Type + "> " + s.Name.Substring(0, 1).ToUpper() + s.Name.Substring(1, s.Name.Length - 1) + "\r\n"; content += " {\r\n"; content += " get\r\n"; content += " {\r\n"; content += " return _" + s.Name + ";\r\n"; content += " }\r\n"; content += "\r\n"; content += " set\r\n"; content += " {\r\n"; content += " _" + s.Name + " = value;\r\n"; if (type == 0) { content += " RaisePropertyChanged(\"" + s.Name.Substring(0, 1).ToUpper() + s.Name.Substring(1, s.Name.Length - 1) + "\");\r\n"; } content += " }\r\n"; content += " }\r\n"; content += "\r\n"; return(content); }
/// <summary> /// 解析载入的VO文件 /// </summary> public void Analysis() { XmlElement rootElement = _document.DocumentElement; //获取根节点 XmlNodeList complexTypeNodes = rootElement.GetElementsByTagName(ConstField.ComplexType); //获取complexType子节点集合 foreach (XmlNode complexTypeNode in complexTypeNodes) { AnalysisVo vo = new AnalysisVo(); XmlElement voElement = (XmlElement)complexTypeNode; string nameVo = voElement.GetAttribute("name"); //获取类的名字 string noteVo = voElement.FirstChild.InnerText; //获取类的注释 List <AnalysisVo> childrenList = new List <AnalysisVo>(); XmlNodeList elementNodes = voElement.GetElementsByTagName(ConstField.Element);//获取element子节点集合 foreach (XmlNode elementNode in elementNodes) { AnalysisVo childVo = new AnalysisVo(); XmlElement fieldElement = (XmlElement)elementNode; string nameField = fieldElement.GetAttribute("name"); //获取字段名字 string typeField = fieldElement.GetAttribute("type"); //获取字段类型 string noteField = ""; //获取字段注释 if (fieldElement.FirstChild != null) { noteField = fieldElement.FirstChild.InnerText; } childVo.Name = nameField; childVo.Type = typeField; childVo.Note = noteField; childrenList.Add(childVo); } vo.Name = nameVo; vo.Note = noteVo; vo.Children = childrenList; VoList.Add(vo); } }
/// <summary> /// 替换Type相应字段 /// </summary> /// <param name="node"></param> private void ReplaceContent(AnalysisVo node) { //正常在基础的字段表中存在 if (DicType.ContainsKey(node.Type)) { node.Type = DicType[node.Type]; }//要解析的里面没有type字段,只有name字段 yanc 20160304 else if (string.IsNullOrEmpty(node.Type) && DicType.ContainsKey(node.Name)) { node.Type = DicType[node.Name]; } else//List类型的没有存储在基础的字段表中,需要循环遍历本身的List列表 if (!string.IsNullOrEmpty(node.Type) && (node.Type.Substring(node.Type.Length - 4, 4).Equals("Grid") || node.Type.Substring(node.Type.Length - 4, 4).Equals("List"))) { foreach (var root in VoList) { if (root.Name.Equals(node.Type)) { node.Type = root.Children.First().Type; } } }//要解析的里面没有type字段,只有name字段 yanc 20160304 else if (string.IsNullOrEmpty(node.Type) && (node.Name.Substring(node.Name.Length - 4, 4).Equals("Grid") || node.Name.Substring(node.Name.Length - 4, 4).Equals("List"))) { foreach (var root in VoList) { if (root.Name.Equals(node.Name)) { node.Type = root.Children.First().Name; } } } else { Console.WriteLine("未能转化的内容" + node.Name); } }