// Registering a built-in highlighting internal void RegisterHighlighting(string name, string[] extensions, string resourceName) { try { #if DEBUG // don't use lazy-loading in debug builds, show errors immediately Xshd.XshdSyntaxDefinition xshd; using (Stream s = Resources.OpenStream(resourceName)) { using (XmlTextReader reader = new XmlTextReader(s)) { xshd = Xshd.HighlightingLoader.LoadXshd(reader, false); } } RegisterHighlighting(name, extensions, Xshd.HighlightingLoader.Load(xshd, this)); #else RegisterHighlighting(name, extensions, LoadHighlighting(resourceName)); #endif } catch (HighlightingDefinitionInvalidException ex) { throw new InvalidOperationException("The built-in highlighting '" + name + "' is invalid.", ex); } }
// Registering a built-in highlighting internal void RegisterHighlighting(string name, string[] extensions, string resourceName) { try { #if DEBUG // don't use lazy-loading in debug builds, show errors immediately Xshd.XshdSyntaxDefinition xshd; using (Stream s = Resources.OpenStream(resourceName)) { using (XmlTextReader reader = new XmlTextReader(s)) { xshd = Xshd.HighlightingLoader.LoadXshd(reader, false); } } Debug.Assert(name == xshd.Name); if (extensions != null) { Debug.Assert(System.Linq.Enumerable.SequenceEqual(extensions, xshd.Extensions)); } else { Debug.Assert(xshd.Extensions.Count == 0); } // // round-trip xshd: // using (XmlTextWriter writer = new XmlTextWriter("c:\\temp\\" + resourceName, System.Text.Encoding.UTF8)) { // writer.Formatting = Formatting.Indented; // new Xshd.SaveXshdVisitor(writer).WriteDefinition(xshd); // } RegisterHighlighting(name, extensions, Xshd.HighlightingLoader.Load(xshd, this)); #else RegisterHighlighting(name, extensions, LoadHighlighting(resourceName)); #endif } catch (HighlightingDefinitionInvalidException ex) { throw new InvalidOperationException("The built-in highlighting '" + name + "' is invalid.", ex); } }
Func<IHighlightingDefinition> LoadHighlighting(string resourceName) { Func<IHighlightingDefinition> func = delegate { Xshd.XshdSyntaxDefinition xshd; using (Stream s = Resources.OpenStream(resourceName)) { using (XmlTextReader reader = new XmlTextReader(s)) { // in release builds, skip validating the built-in highlightings xshd = Xshd.HighlightingLoader.LoadXshd(reader, true); } } return Xshd.HighlightingLoader.Load(xshd, this); }; return func; }
// Registering a built-in highlighting internal void RegisterHighlighting(string name, string[] extensions, string resourceName) { try { #if DEBUG // don't use lazy-loading in debug builds, show errors immediately Xshd.XshdSyntaxDefinition xshd; using (Stream s = Resources.OpenStream(resourceName)) { using (XmlTextReader reader = new XmlTextReader(s)) { xshd = Xshd.HighlightingLoader.LoadXshd(reader, false); } } Debug.Assert(name == xshd.Name); if (extensions != null) { Debug.Assert(System.Linq.Enumerable.SequenceEqual(extensions, xshd.Extensions)); } else { Debug.Assert(xshd.Extensions.Count == 0); } // round-trip xshd: string resourceFileName = Path.Combine(Path.GetTempPath(), resourceName); using (XmlTextWriter writer = new XmlTextWriter(resourceFileName, System.Text.Encoding.UTF8)) { writer.Formatting = Formatting.Indented; new Xshd.SaveXshdVisitor(writer).WriteDefinition(xshd); } using (FileStream fs = File.Create(resourceFileName + ".bin")) { new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(fs, xshd); } using (FileStream fs = File.Create(resourceFileName + ".compiled")) { new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(fs, Xshd.HighlightingLoader.Load(xshd, this)); } RegisterHighlighting(name, extensions, Xshd.HighlightingLoader.Load(xshd, this)); #else RegisterHighlighting(name, extensions, LoadHighlighting(resourceName)); #endif } catch (HighlightingDefinitionInvalidException ex) { throw new InvalidOperationException("The built-in highlighting '" + name + "' is invalid.", ex); } }