Skip to content

Commit 995d31f

Browse files
Fix #3318: missing x:FieldModifier in BAML decompiler
1 parent d736b02 commit 995d31f

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
using System.Reflection.Metadata;
2323
using System.Xml.Linq;
2424

25+
using ICSharpCode.BamlDecompiler.Xaml;
2526
using ICSharpCode.Decompiler.CSharp;
2627
using ICSharpCode.Decompiler.IL;
2728
using ICSharpCode.Decompiler.IL.Transforms;
2829
using ICSharpCode.Decompiler.Util;
2930

30-
using ICSharpCode.BamlDecompiler.Xaml;
31-
3231
namespace ICSharpCode.BamlDecompiler.Rewrite
3332
{
3433
using ICSharpCode.Decompiler.TypeSystem;
@@ -67,6 +66,11 @@ static void ProcessConnectionIds(XamlContext ctx, XElement element,
6766
{
6867
element.Add(new XAttribute(xName, fieldAssignment.Field.Name));
6968
}
69+
// x:FieldModifier can only be "public" or "internal" (in C#), where "internal" is the default and thus omitted
70+
if (fieldAssignment.Field.Accessibility is Accessibility.Public)
71+
{
72+
element.Add(new XAttribute(ctx.GetKnownNamespace("FieldModifier", XamlContext.KnownNamespace_Xaml, element), "public"));
73+
}
7074
ctx.GeneratedMembers.Add(fieldAssignment.Field.MetadataToken);
7175
found = true;
7276
}

ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20-
using System.Collections;
2120
using System.IO;
2221
using System.Linq;
23-
using System.Threading;
2422
using System.Xml.Linq;
2523

2624
using ICSharpCode.BamlDecompiler;
@@ -155,6 +153,12 @@ public void Issue2116()
155153
RunTest("cases/issue2116");
156154
}
157155

156+
[Test]
157+
public void Issue3318()
158+
{
159+
RunTest("cases/issue3318");
160+
}
161+
158162
[Test]
159163
public void ReadonlyProperty()
160164
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<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">
2+
<Grid Name="Root" x:FieldModifier="public" />
3+
</UserControl>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Shapes;
13+
14+
namespace ILSpy.BamlDecompiler.Tests.Cases
15+
{
16+
/// <summary>
17+
/// Interaction logic for Issue3318.xaml
18+
/// </summary>
19+
public partial class Issue3318 : UserControl
20+
{
21+
public Issue3318()
22+
{
23+
InitializeComponent();
24+
}
25+
}
26+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Cases\Issue1547.xaml.cs" />
6363
<Compile Include="Cases\Issue2097.xaml.cs" />
6464
<Compile Include="Cases\Issue2116.xaml.cs" />
65+
<Compile Include="Cases\Issue3318.xaml.cs" />
6566
<Compile Include="Cases\MyControl.xaml.cs">
6667
<DependentUpon>MyControl.xaml</DependentUpon>
6768
</Compile>
@@ -104,6 +105,9 @@
104105
<Page Include="Cases\Issue2116.xaml">
105106
<Generator>MSBuild:Compile</Generator>
106107
</Page>
108+
<Page Include="Cases\Issue3318.xaml">
109+
<Generator>MSBuild:Compile</Generator>
110+
</Page>
107111
<Page Include="Cases\Issue775.xaml">
108112
<SubType>Designer</SubType>
109113
</Page>

0 commit comments

Comments
 (0)