public Technique(string file) { Name = file; vsdefines_ = new ObservableCollection <string>(); psdefines_ = new ObservableCollection <string>(); passes_ = new ObservableCollection <Pass>(); XmlDocument doc = new XmlDocument(); doc.Load(file); XmlElement root = doc.DocumentElement; if (root.HasAttribute("vs")) { VS = root.GetAttribute("vs"); } if (root.HasAttribute("ps")) { PS = root.GetAttribute("ps"); } if (root.HasAttribute("vsdefines")) { string[] defs = root.GetAttribute("vsdefines").Split(' '); foreach (string str in defs) { VSDefines.Add(str); } } if (root.HasAttribute("psdefines")) { string[] defs = root.GetAttribute("psdefines").Split(' '); foreach (string str in defs) { PSDefines.Add(str); } } if (root.HasAttribute("sm3")) { IsSM3 = root.GetAttribute("sm3").Equals("true"); } if (root.HasAttribute("desktop")) { IsDesktop = root.GetAttribute("desktop").Equals("true"); } foreach (XmlElement e in root.ChildNodes) { if (e.Name.Equals("pass")) { Pass p = new Pass(); p.Parse(e); Passes.Add(p); } } }
public override void Save() { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("technique"); doc.AppendChild(root); if (VS != null && VS.Length > 0) { root.SetAttribute("vs", VS); } if (PS != null && PS.Length > 0) { root.SetAttribute("ps", PS); } if (VSDefines.Count > 0) { root.SetAttribute("vsdefines", string.Join(" ", VSDefines.ToArray())); } if (PSDefines.Count > 0) { root.SetAttribute("psdefines", string.Join(" ", PSDefines.ToArray())); } if (IsSM3.HasValue) { root.SetAttribute("sm3", IsSM3.Value ? "true" : "false"); } if (IsDesktop.HasValue) { root.SetAttribute("desktop", IsDesktop.Value ? "true" : "false"); } foreach (Pass pass in Passes) { root.AppendChild(pass.Save(doc)); } XmlWriterSettings xws = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }; using (XmlWriter xw = XmlWriter.Create(System.IO.Path.ChangeExtension(Name, "xml"), xws)) doc.Save(xw); }