Ejemplo n.º 1
0
 public XMLHelper(string xmlpath)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(xmlpath))
         {
             throw new Exception(YeahExceptionDesc.ExceptionDesc(YeahExceptionType.InvalidFilePath));
         }
     }
     finally
     {
         this.xmlfilepath = xmlpath;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据XMl节点,批量创建类.
        /// </summary>
        /// <returns><c>true</c>, if entity by xml was created, <c>false</c> otherwise.</returns>
        public bool CreateClassByXML(string outputFolder)
        {
            try
            {
                if (File.Exists(xmlfilepath))
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlfilepath);
                    //取根结点
                    var root = xmlDoc.DocumentElement;//取到根结点

                    TravelNode(root);


                    string outStr = Statement(0, "using System;\r\nusing System.Xml;\r\nusing YeahException;\r\nusing System.Collections.Generic;");
                    outStr += Statement(0, "\r\nnamespace YeahTools." + Path.GetFileNameWithoutExtension(xmlfilepath));
                    outStr += BeginSignal(0);

                    foreach (XmlNodeClass nodeclass in distinctnodes)
                    {
                        outStr += NodeToClass(nodeclass.ClassName, nodeclass.ParentClassName, nodeclass.PtyList, nodeclass.ChildMemberList);
                    }

                    outStr += EndSignal(0);

                    StreamWriter sw = new StreamWriter(Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(xmlfilepath) + "Helper.cs"));
                    sw.Write(outStr);
                    sw.Flush();
                    sw.Close();
                    return(true);
                }
                else
                {
                    throw new Exception(YeahExceptionDesc.ExceptionDesc(YeahExceptionType.FileNotExists));
                }
            }
            catch (SystemException ex)
            {
                return(false);
            }
        }