From fc92c17146e42e7e533e69130b4695303fc1f744 Mon Sep 17 00:00:00 2001 From: Schabse Laks Date: Sun, 9 Nov 2014 12:05:43 -0500 Subject: [PATCH] BamlDecompiler: Correctly qualify types in nested {x:Static} extensions Includes failing test case --- .../XmlBamlReader.cs | 30 +++++++++---------- .../Tests/Cases/CustomControl.cs | 2 ++ .../Tests/Cases/NamespacePrefix.xaml | 4 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index bd1cf120a..4e330f471 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -868,11 +868,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection switch (x) { case 0x25a: // StaticExtension - object resource = this.GetResourceName(valueIdentifier); - if (resource is ResourceName) - value = this.GetStaticExtension(((ResourceName)resource).Name); - else if (resource is PropertyDeclaration) - value = this.GetStaticExtension(FormatPropertyDeclaration(((PropertyDeclaration)resource), true, false, false)); + value = this.GetStaticExtension(this.GetResourceName(valueIdentifier)); break; case 0x25b: // StaticResource case 0xbd: // DynamicResource @@ -883,7 +879,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection else if (isStaticType) { TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier); - value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier).ToString())); + value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier))); } else { @@ -1449,15 +1445,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection if (isValueType) resource = GetTypeExtension(typeIdentifier); else if (isStaticType) { - object name = GetResourceName(typeIdentifier); - if (name == null) - resource = null; - else if (name is ResourceName) - resource = GetStaticExtension(((ResourceName)name).Name); - else if (name is PropertyDeclaration) - resource = GetStaticExtension(FormatPropertyDeclaration(((PropertyDeclaration)name), true, false, false)); - else - throw new InvalidOperationException("Invalid resource: " + name.GetType()); + resource = GetStaticExtension(GetResourceName(typeIdentifier)); } else { resource = this.stringTable[typeIdentifier]; } @@ -1473,8 +1461,18 @@ namespace Ricciolo.StylesExplorer.MarkupReflection return String.Format("{{TemplateBinding {0}}}", FormatPropertyDeclaration(propertyDeclaration, true, false, false)); } - string GetStaticExtension(string name) + string GetStaticExtension(object resource) { + if (resource == null) + return null; + string name; + if (resource is ResourceName) + name = ((ResourceName)resource).Name; + else if (resource is PropertyDeclaration) + name = this.FormatPropertyDeclaration(((PropertyDeclaration)resource), true, false, false); + else + throw new InvalidOperationException("Invalid resource: " + resource.GetType()); + string prefix = this.LookupPrefix(XmlPIMapping.XamlNamespace, false); if (String.IsNullOrEmpty(prefix)) return String.Format("{{Static {0}}}", name); diff --git a/ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs b/ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs index f85c51a4e..e48b20d8a 100644 --- a/ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs +++ b/ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs @@ -10,6 +10,8 @@ namespace ILSpy.BamlDecompiler.Tests.Cases { public class CustomControl : ContentControl { + public static string SimpleProperty = "Hi!"; + public static readonly DependencyProperty CustomNameProperty = DependencyProperty.RegisterAttached("CustomName", typeof(string), typeof(CustomControl)); public static string GetCustomName(DependencyObject target) diff --git a/ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml b/ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml index 5fb529054..eb370b734 100644 --- a/ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml +++ b/ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml @@ -1,4 +1,4 @@ - +