Skip to content

Instantly share code, notes, and snippets.

@osya
Last active December 2, 2015 20:50
Show Gist options
  • Save osya/1707c0812cfc9b803b7b to your computer and use it in GitHub Desktop.
Save osya/1707c0812cfc9b803b7b to your computer and use it in GitHub Desktop.
XAML Reader Loop Examples #XAML #CSharp
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