diff --git a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs index 71c5f4131..b79492d1f 100644 --- a/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs +++ b/ILSpy.BamlDecompiler/BamlResourceEntryNode.cs @@ -45,17 +45,11 @@ namespace ILSpy.BamlDecompiler return true; } - const string XWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; - const string DefaultWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; - bool LoadBaml(AvalonEditTextOutput output) { var asm = this.Ancestors().OfType().FirstOrDefault().LoadedAssembly; Data.Position = 0; - - XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data); - output.Write(xamlDocument.ToString()); return true; } @@ -73,18 +67,18 @@ namespace ILSpy.BamlDecompiler static void MoveNamespacesToRoot(XDocument xamlDocument) { var additionalXmlns = new List { - new XAttribute("xmlns", DefaultWPFNamespace), - new XAttribute(XName.Get("x", XNamespace.Xmlns.NamespaceName), XWPFNamespace) + new XAttribute("xmlns", XmlBamlReader.DefaultWPFNamespace), + new XAttribute(XName.Get("x", XNamespace.Xmlns.NamespaceName), XmlBamlReader.XWPFNamespace) }; foreach (var element in xamlDocument.Root.DescendantsAndSelf()) { - if (element.Name.NamespaceName != DefaultWPFNamespace && !additionalXmlns.Any(ka => ka.Value == element.Name.NamespaceName)) { + if (element.Name.NamespaceName != XmlBamlReader.DefaultWPFNamespace && !additionalXmlns.Any(ka => ka.Value == element.Name.NamespaceName)) { string newPrefix = new string(element.Name.LocalName.Where(c => char.IsUpper(c)).ToArray()).ToLowerInvariant(); int current = additionalXmlns.Count(ka => ka.Name.Namespace == XNamespace.Xmlns && ka.Name.LocalName.TrimEnd(ch => char.IsNumber(ch)) == newPrefix); if (current > 0) newPrefix += (current + 1).ToString(); XName defaultXmlns = XName.Get(newPrefix, XNamespace.Xmlns.NamespaceName); - if (element.Name.NamespaceName != DefaultWPFNamespace) + if (element.Name.NamespaceName != XmlBamlReader.DefaultWPFNamespace) additionalXmlns.Add(new XAttribute(defaultXmlns, element.Name.NamespaceName)); } } diff --git a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj index c87d30781..a681f07fd 100644 --- a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj +++ b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj @@ -98,6 +98,7 @@ + diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index ccb790df6..6417549f7 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -55,6 +55,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection private readonly TypeDeclaration XamlTypeDeclaration; private readonly XmlNameTable _nameTable = new NameTable(); private IDictionary _rootNamespaces; + + public const string XWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; + public const string DefaultWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; #endregion @@ -160,7 +163,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection public override bool MoveToFirstAttribute() { intoAttribute = false; - if (nodes.Count > 0 && nodes.Peek() is XmlBamlProperty) + if (nodes.Count > 0 && (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty)) { _currentNode = nodes.Dequeue(); return true; @@ -179,7 +182,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection public override bool MoveToNextAttribute() { intoAttribute = false; - if (nodes.Count > 0 && nodes.Peek() is XmlBamlProperty) + if (nodes.Count > 0 && (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty)) { _currentNode = nodes.Dequeue(); return true; @@ -197,7 +200,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection /// public override bool MoveToElement() { - while (nodes.Peek() is XmlBamlProperty) + while (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty) { nodes.Dequeue(); } @@ -295,6 +298,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection _currentNode = nodes.Dequeue(); if ((_currentNode is XmlBamlProperty)) continue; + if ((_currentNode is XmlBamlSimpleProperty)) continue; if (this.NodeType == XmlNodeType.EndElement) { @@ -580,7 +584,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection String localName = String.Empty; XmlBamlNode node = this.CurrentNode; - if (node is XmlBamlProperty) + if (node is XmlBamlSimpleProperty) { + var simpleNode = (XmlBamlSimpleProperty)node; + localName = simpleNode.LocalName; + } else if (node is XmlBamlProperty) { PropertyDeclaration pd = ((XmlBamlProperty)node).PropertyDeclaration; localName = FormatPropertyDeclaration(pd, false, true, true); @@ -1185,13 +1192,19 @@ namespace Ricciolo.StylesExplorer.MarkupReflection // the type is defined in the local assembly, i.e., the main assembly // and this is the root element + TypeDeclaration oldDeclaration = null; if (_resolver.IsLocalAssembly(declaration.Assembly) && parentElement == null) { + oldDeclaration = declaration; declaration = GetKnownTypeDeclarationByName(declaration.Type.BaseType.AssemblyQualifiedName); } element.TypeDeclaration = declaration; elements.Push(element); nodes.Enqueue(element); + + if (oldDeclaration != null) { + nodes.Enqueue(new XmlBamlSimpleProperty(XWPFNamespace, "Class", string.Format("{0}.{1}", oldDeclaration.Namespace, oldDeclaration.Name))); + } if (parentElement != null && complexPropertyOpened == 0) { @@ -1609,7 +1622,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection TypeDeclaration declaration; XmlBamlNode node = this.CurrentNode; - if (node is XmlBamlProperty) + if (node is XmlBamlSimpleProperty) + return ((XmlBamlSimpleProperty)node).NamespaceName; + else if (node is XmlBamlProperty) { declaration = ((XmlBamlProperty)node).PropertyDeclaration.DeclaringType; TypeDeclaration elementDeclaration = this.readingElements.Peek().TypeDeclaration; @@ -1685,7 +1700,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection get { XmlBamlNode node = this.CurrentNode; - if (node is XmlBamlProperty) + if (node is XmlBamlSimpleProperty) + return ((XmlBamlSimpleProperty)node).Value; + else if (node is XmlBamlProperty) return ((XmlBamlProperty)node).Value.ToString(); else if (node is XmlBamlText) return ((XmlBamlText)node).Text; diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlSimpleProperty.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlSimpleProperty.cs new file mode 100644 index 000000000..be00e41e1 --- /dev/null +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlSimpleProperty.cs @@ -0,0 +1,34 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team +// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace Ricciolo.StylesExplorer.MarkupReflection +{ + class XmlBamlSimpleProperty : XmlBamlNode + { + public string NamespaceName { get; private set; } + public string LocalName { get; private set; } + public string Value { get; private set; } + + public XmlBamlSimpleProperty(string namespaceName, string localName, string value) + { + if (string.IsNullOrWhiteSpace(namespaceName)) + throw new ArgumentException("namespaceName"); + if (string.IsNullOrWhiteSpace(localName)) + throw new ArgumentException("localName"); + if (value == null) + throw new ArgumentNullException("value"); + this.NamespaceName = namespaceName; + this.LocalName = localName; + this.Value = value; + } + + public override XmlNodeType NodeType { + get { return XmlNodeType.Attribute; } + } + } +}