Skip to content

Commit

Permalink
BamlDecompiler: Correctly qualify types in nested {x:Static} extensions
Browse files Browse the repository at this point in the history
Includes failing test case
  • Loading branch information
SLaks committed Nov 13, 2014
1 parent a796143 commit fc92c17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,7 @@ void ReadPropertyWithExtension()
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
Expand All @@ -883,7 +879,7 @@ void ReadPropertyWithExtension()
else if (isStaticType)
{
TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier);
value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier).ToString()));
value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier)));
}
else
{
Expand Down Expand Up @@ -1449,15 +1445,7 @@ void ReadOptimizedStaticResource()
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];
}
Expand All @@ -1473,8 +1461,18 @@ string GetTemplateBindingExtension(PropertyDeclaration propertyDeclaration)
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);
Expand Down
2 changes: 2 additions & 0 deletions ILSpy.BamlDecompiler/Tests/Cases/CustomControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<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.Style>
<Style />
</cc:CustomControl.Style>
<Grid.Row>0</Grid.Row>
<cc:CustomControl.CustomName>Custom1</cc:CustomControl.CustomName>
</cc:CustomControl>
<Label>
<Label ToolTip="{DynamicResource {x:Static cc:CustomControl.SimpleProperty}}">
<Label.Style>
<Style />
</Label.Style>
Expand Down

0 comments on commit fc92c17

Please sign in to comment.