Last active
December 2, 2015 20:50
-
-
Save osya/1707c0812cfc9b803b7b to your computer and use it in GitHub Desktop.
XAML Reader Loop Examples #XAML #CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XmlReader xmlReader = XmlReader.Create(input); | |
XamlXmlReader reader = new XamlXmlReader(xmlReader, System.Windows.Markup.XamlReader.GetWpfSchemaContext()); | |
XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext); | |
while (reader.Read()) | |
{ | |
switch (reader.NodeType) | |
{ | |
case XamlNodeType.StartObject: | |
if (!reader.Type.Name.Equals("Window")) | |
writer.WriteNode(reader); | |
else | |
writer.WriteStartObject(new XamlType(typeof(Page), reader.SchemaContext)); | |
break; | |
case XamlNodeType.EndObject: | |
case XamlNodeType.StartMember: | |
case XamlNodeType.EndMember: | |
case XamlNodeType.Value: | |
case XamlNodeType.GetObject: | |
case XamlNodeType.NamespaceDeclaration: | |
writer.WriteNode(reader); | |
break; | |
} | |
} | |
using(var reader = new XamlXmlReader(path)) { | |
using(var writer = new XamlObjectWriter(new XamlSchemaContext())) { | |
while(reader.Read()) { | |
switch(reader.NodeType) { | |
case XamlNodeType.StartObject: | |
writer.WriteNode(reader); | |
break; | |
case XamlNodeType.StartMember: | |
goto default; | |
case XamlNodeType.EndObject: | |
writer.WriteNode(reader); | |
AnalyzeObject(writer.Result); | |
break; | |
default: | |
writer.WriteNode(reader); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment