Browse Source

Merge pull request #2536 from wwh1004/fix-xaml-prop-with-ext

Fix missing x:Static and x:Type in decompiled BAML
pull/2542/head
Siegfried Pammer 4 years ago committed by GitHub
parent
commit
74630109b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  2. 15
      ILSpy.BamlDecompiler.Tests/Cases/Issue2116.xaml
  3. 16
      ILSpy.BamlDecompiler.Tests/Cases/Issue2116.xaml.cs
  4. 4
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  5. 14
      ILSpy.BamlDecompiler/Handlers/Records/PropertyWithExtensionHandler.cs

6
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -148,6 +148,12 @@ namespace ILSpy.BamlDecompiler.Tests
RunTest("cases/issue2097"); RunTest("cases/issue2097");
} }
[Test]
public void Issue2116()
{
RunTest("cases/issue2116");
}
#region RunTest #region RunTest
void RunTest(string name) void RunTest(string name)
{ {

15
ILSpy.BamlDecompiler.Tests/Cases/Issue2116.xaml

@ -0,0 +1,15 @@
<UserControl x:Class="ILSpy.BamlDecompiler.Tests.Cases.Issue2116" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<FrameworkElement.Resources>
<ResourceDictionary>
<Style x:Key="TestStyle1" />
<Style x:Key="TestStyle2" BasedOn="{StaticResource TestStyle1}" />
<Style x:Key="TestStyle2" BasedOn="{StaticResource {x:Type local:Issue2116}}" />
<Style x:Key="TestStyle2" BasedOn="{StaticResource {x:Static local:Issue2116.StyleKey1}}" />
</ResourceDictionary>
</FrameworkElement.Resources>
<Grid>
<Grid Style="{StaticResource TestStyle1}" />
<Grid Style="{StaticResource {x:Type local:Issue2116}}" />
<Grid Style="{StaticResource {x:Static local:Issue2116.StyleKey1}}" />
</Grid>
</UserControl>

16
ILSpy.BamlDecompiler.Tests/Cases/Issue2116.xaml.cs

@ -0,0 +1,16 @@
namespace ILSpy.BamlDecompiler.Tests.Cases
{
using System.Windows;
using System.Windows.Controls;
public partial class Issue2116 : UserControl
{
public static ComponentResourceKey StyleKey1 => new ComponentResourceKey(typeof(Issue2116), "TestStyle1");
public static ComponentResourceKey StyleKey2 => new ComponentResourceKey(typeof(Issue2116), "TestStyle2");
public Issue2116()
{
InitializeComponent();
}
}
}

4
ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -59,6 +59,7 @@
<Compile Include="Cases\CustomControl.cs" /> <Compile Include="Cases\CustomControl.cs" />
<Compile Include="Cases\Issue1547.xaml.cs" /> <Compile Include="Cases\Issue1547.xaml.cs" />
<Compile Include="Cases\Issue2097.xaml.cs" /> <Compile Include="Cases\Issue2097.xaml.cs" />
<Compile Include="Cases\Issue2116.xaml.cs" />
<Compile Include="Cases\MyControl.xaml.cs"> <Compile Include="Cases\MyControl.xaml.cs">
<DependentUpon>MyControl.xaml</DependentUpon> <DependentUpon>MyControl.xaml</DependentUpon>
</Compile> </Compile>
@ -99,6 +100,9 @@
<Page Include="Cases\Issue2097.xaml"> <Page Include="Cases\Issue2097.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Cases\Issue2116.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue775.xaml"> <Page Include="Cases\Issue775.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>

14
ILSpy.BamlDecompiler/Handlers/Records/PropertyWithExtensionHandler.cs

@ -47,7 +47,12 @@ namespace ILSpy.BamlDecompiler.Handlers
if (valTypeExt || extTypeId == (short)KnownTypes.TypeExtension) if (valTypeExt || extTypeId == (short)KnownTypes.TypeExtension)
{ {
var value = ctx.ResolveType(record.ValueId); var value = ctx.ResolveType(record.ValueId);
ext.Initializer = new object[] { ctx.ToString(parent.Xaml, value) };
object[] initializer = new object[] { ctx.ToString(parent.Xaml, value) };
if (valTypeExt)
initializer = new object[] { new XamlExtension(ctx.ResolveType(0xfd4d)) { Initializer = initializer } }; // Known type - TypeExtension
ext.Initializer = initializer;
} }
else if (extTypeId == (short)KnownTypes.TemplateBindingExtension) else if (extTypeId == (short)KnownTypes.TemplateBindingExtension)
{ {
@ -97,7 +102,12 @@ namespace ILSpy.BamlDecompiler.Handlers
attrName = ctx.ToString(parent.Xaml, xName); attrName = ctx.ToString(parent.Xaml, xName);
} }
ext.Initializer = new object[] { attrName };
object[] initializer = new object[] { attrName };
if (valStaticExt)
initializer = new object[] { new XamlExtension(ctx.ResolveType(0xfda6)) { Initializer = initializer } }; // Known type - StaticExtension
ext.Initializer = initializer;
} }
else else
{ {

Loading…
Cancel
Save