Browse Source

BamlDecompiler: Correctly qualify types in nested {x:Static} extensions

Includes failing test case
pull/515/head
Schabse Laks 11 years ago committed by SLaks
parent
commit
fc92c17146
  1. 30
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  2. 2
      ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs
  3. 4
      ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml

30
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -868,11 +868,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
switch (x) { switch (x) {
case 0x25a: case 0x25a:
// StaticExtension // StaticExtension
object resource = this.GetResourceName(valueIdentifier); value = this.GetStaticExtension(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));
break; break;
case 0x25b: // StaticResource case 0x25b: // StaticResource
case 0xbd: // DynamicResource case 0xbd: // DynamicResource
@ -883,7 +879,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
else if (isStaticType) else if (isStaticType)
{ {
TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier); TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier);
value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier).ToString())); value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier)));
} }
else else
{ {
@ -1449,15 +1445,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (isValueType) if (isValueType)
resource = GetTypeExtension(typeIdentifier); resource = GetTypeExtension(typeIdentifier);
else if (isStaticType) { else if (isStaticType) {
object name = GetResourceName(typeIdentifier); resource = GetStaticExtension(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());
} else { } else {
resource = this.stringTable[typeIdentifier]; resource = this.stringTable[typeIdentifier];
} }
@ -1473,8 +1461,18 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return String.Format("{{TemplateBinding {0}}}", FormatPropertyDeclaration(propertyDeclaration, true, false, false)); 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); string prefix = this.LookupPrefix(XmlPIMapping.XamlNamespace, false);
if (String.IsNullOrEmpty(prefix)) if (String.IsNullOrEmpty(prefix))
return String.Format("{{Static {0}}}", name); return String.Format("{{Static {0}}}", name);

2
ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs

@ -10,6 +10,8 @@ namespace ILSpy.BamlDecompiler.Tests.Cases
{ {
public class CustomControl : ContentControl public class CustomControl : ContentControl
{ {
public static string SimpleProperty = "Hi!";
public static readonly DependencyProperty CustomNameProperty = DependencyProperty.RegisterAttached("CustomName", typeof(string), typeof(CustomControl)); public static readonly DependencyProperty CustomNameProperty = DependencyProperty.RegisterAttached("CustomName", typeof(string), typeof(CustomControl));
public static string GetCustomName(DependencyObject target) public static string GetCustomName(DependencyObject target)

4
ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml

@ -1,4 +1,4 @@
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:cc="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases"> <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cc="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases">
<cc:CustomControl> <cc:CustomControl>
<cc:CustomControl.Style> <cc:CustomControl.Style>
<Style /> <Style />
@ -6,7 +6,7 @@
<Grid.Row>0</Grid.Row> <Grid.Row>0</Grid.Row>
<cc:CustomControl.CustomName>Custom1</cc:CustomControl.CustomName> <cc:CustomControl.CustomName>Custom1</cc:CustomControl.CustomName>
</cc:CustomControl> </cc:CustomControl>
<Label> <Label ToolTip="{DynamicResource {x:Static cc:CustomControl.SimpleProperty}}">
<Label.Style> <Label.Style>
<Style /> <Style />
</Label.Style> </Label.Style>

Loading…
Cancel
Save