예제 #1
0
 public void SetParent(StructEntity parent)
 {
     if (Parent == null)
     {
         Parent = parent;
     }
 }
예제 #2
0
        public bool FromXml(string fileName)
        {
            structs.Clear();
            tables.Clear();
            FileName = Path.GetFullPath(fileName);
            XDocument doc          = XDocument.Load(FileName);
            var       root         = doc.Element("Root");
            var       commonStruct = root.Element("CommonStruct");

            foreach (var el in commonStruct.Elements("Struct"))
            {
                StructEntity st = new StructEntity();
                if (!st.FromXml(el))
                {
                    ErrorMessage.Error("xml文件{0}", FileName);
                    return(false);
                }
                if (structs.Exists(obj => obj.Name == st.Name))
                {
                    ErrorMessage.Error("xml文件{0}含有同名的 Struct {1} {2}", FileName, st.Name, el.ToString());
                    return(false);
                }
                structs.Add(st);
            }
            var table = root.Element("Table");

            foreach (var el in table.Elements())
            {
                TableEntity tb = null;
                if (el.Name == "Row")
                {
                    tb = new RowTableEntity();
                }
                else if (el.Name == "Column")
                {
                    tb = new ColumnTableEntity();
                }
                else
                {
                    continue;
                }
                if (!tb.FromXml(el))
                {
                    ErrorMessage.Error("xml文件{0}", FileName);
                    return(false);
                }
                if (tables.Exists(obj => obj.Name == tb.Name))
                {
                    ErrorMessage.Error("xml文件{0}含有同名的 Table {1} {2}", FileName, tb.Name, el.ToString());
                    return(false);
                }
                tables.Add(tb);
            }
            return(true);
        }