Browse Source

Fix #1435: bug in x:Name handling.

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
ab16a77e54
  1. 6
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  2. 3
      ILSpy.BamlDecompiler.Tests/Cases/Issue1435.xaml
  3. 3
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  4. 19
      ILSpy.BamlDecompiler/Handlers/Records/PropertyHandler.cs

6
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -101,6 +101,12 @@ namespace ILSpy.BamlDecompiler.Tests
RunTest("cases/escapesequence");
}
[Test]
public void Issue1435()
{
RunTest("cases/issue1435");
}
#region RunTest
void RunTest(string name)
{

3
ILSpy.BamlDecompiler.Tests/Cases/Issue1435.xaml

@ -0,0 +1,3 @@
<UserControl x:Class="ILSpy.BamlDecompiler.Tests.Cases.Issue1435" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases" x:Name="SomeControlName" AutomationProperties.Name="SomeAutomationName">
<Grid Name="SomeControlName2" AutomationProperties.Name="SomeAutomationName2" />
</UserControl>

3
ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -76,6 +76,9 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue1435.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue775.xaml">
<SubType>Designer</SubType>
</Page>

19
ILSpy.BamlDecompiler/Handlers/Records/PropertyHandler.cs

@ -35,15 +35,20 @@ namespace ILSpy.BamlDecompiler.Handlers {
var xamlProp = ctx.ResolveProperty(record.AttributeId);
var value = XamlUtils.Escape(record.Value);
XAttribute attr;
if (xamlProp.PropertyName == "Name" && elemType.ResolvedType.GetDefinition()?.ParentModule.IsMainModule == true) {
attr = new XAttribute(ctx.GetXamlNsName("Name"), value);
} else {
attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value);
}
parent.Xaml.Element.Add(attr);
parent.Xaml.Element.Add(ConstructXAttribute());
return null;
XAttribute ConstructXAttribute()
{
if (xamlProp.IsAttachedTo(elemType))
return new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, true), value);
if (xamlProp.PropertyName == "Name" && elemType.ResolvedType.GetDefinition()?.ParentModule.IsMainModule == true)
return new XAttribute(ctx.GetXamlNsName("Name"), value);
return new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, false), value);
}
}
}
}
Loading…
Cancel
Save