Browse Source

Fix #3318: missing x:FieldModifier in BAML decompiler

pull/3592/head
Siegfried Pammer 3 months ago
parent
commit
995d31fc2d
  1. 8
      ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs
  2. 8
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  3. 3
      ILSpy.BamlDecompiler.Tests/Cases/Issue3318.xaml
  4. 26
      ILSpy.BamlDecompiler.Tests/Cases/Issue3318.xaml.cs
  5. 4
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

8
ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs

@ -22,13 +22,12 @@ using System.Linq; @@ -22,13 +22,12 @@ using System.Linq;
using System.Reflection.Metadata;
using System.Xml.Linq;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.Transforms;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.BamlDecompiler.Xaml;
namespace ICSharpCode.BamlDecompiler.Rewrite
{
using ICSharpCode.Decompiler.TypeSystem;
@ -67,6 +66,11 @@ namespace ICSharpCode.BamlDecompiler.Rewrite @@ -67,6 +66,11 @@ namespace ICSharpCode.BamlDecompiler.Rewrite
{
element.Add(new XAttribute(xName, fieldAssignment.Field.Name));
}
// x:FieldModifier can only be "public" or "internal" (in C#), where "internal" is the default and thus omitted
if (fieldAssignment.Field.Accessibility is Accessibility.Public)
{
element.Add(new XAttribute(ctx.GetKnownNamespace("FieldModifier", XamlContext.KnownNamespace_Xaml, element), "public"));
}
ctx.GeneratedMembers.Add(fieldAssignment.Field.MetadataToken);
found = true;
}

8
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -17,10 +17,8 @@ @@ -17,10 +17,8 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml.Linq;
using ICSharpCode.BamlDecompiler;
@ -155,6 +153,12 @@ namespace ILSpy.BamlDecompiler.Tests @@ -155,6 +153,12 @@ namespace ILSpy.BamlDecompiler.Tests
RunTest("cases/issue2116");
}
[Test]
public void Issue3318()
{
RunTest("cases/issue3318");
}
[Test]
public void ReadonlyProperty()
{

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

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
<UserControl x:Class="ILSpy.BamlDecompiler.Tests.Cases.Issue3318" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cases="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases;assembly=ILSpy.BamlDecompiler.Tests">
<Grid Name="Root" x:FieldModifier="public" />
</UserControl>

26
ILSpy.BamlDecompiler.Tests/Cases/Issue3318.xaml.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ILSpy.BamlDecompiler.Tests.Cases
{
/// <summary>
/// Interaction logic for Issue3318.xaml
/// </summary>
public partial class Issue3318 : UserControl
{
public Issue3318()
{
InitializeComponent();
}
}
}

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

@ -62,6 +62,7 @@ @@ -62,6 +62,7 @@
<Compile Include="Cases\Issue1547.xaml.cs" />
<Compile Include="Cases\Issue2097.xaml.cs" />
<Compile Include="Cases\Issue2116.xaml.cs" />
<Compile Include="Cases\Issue3318.xaml.cs" />
<Compile Include="Cases\MyControl.xaml.cs">
<DependentUpon>MyControl.xaml</DependentUpon>
</Compile>
@ -104,6 +105,9 @@ @@ -104,6 +105,9 @@
<Page Include="Cases\Issue2116.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue3318.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue775.xaml">
<SubType>Designer</SubType>
</Page>

Loading…
Cancel
Save