Skip to content

Commit

Permalink
fix icsharpcode#470: BAML to XAML conversion does not generate escape…
Browse files Browse the repository at this point in the history
… sequence {} correctly
  • Loading branch information
siegfriedpammer committed Nov 13, 2014
1 parent 0d82186 commit 0ada95d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@
<Name>ICSharpCode.Decompiler</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="IL" />
<None Include="BooleanConsumedAsInteger.il" />
</ItemGroup>
<ItemGroup>
<None Include="BooleanConsumedAsInteger.il" />
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ void ReadProperty()
short identifier = reader.ReadInt16();
string text = reader.ReadString();

EnqueueProperty(identifier, text);
EnqueueProperty(identifier, EscapeCurlyBraces(text));
}

void ReadPropertyWithConverter()
Expand All @@ -917,7 +917,16 @@ void ReadPropertyWithConverter()
string text = reader.ReadString();
reader.ReadInt16();

EnqueueProperty(identifier, text);
EnqueueProperty(identifier, EscapeCurlyBraces(text));
}

string EscapeCurlyBraces(string text)
{
if (!text.StartsWith("{", StringComparison.OrdinalIgnoreCase))
return text;
if (text.StartsWith("{}", StringComparison.OrdinalIgnoreCase))
return text;
return "{}" + text;
}

bool HaveSeenNestedElement()
Expand Down
26 changes: 26 additions & 0 deletions ILSpy.BamlDecompiler/Tests/Cases/EscapeSequence.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib">
<StackPanel>
<StackPanel.Resources>
<DataTemplate x:Key="key" DataType="{}{http://planetsNS}Planet">
<StackPanel Orientation="Horizontal">
<TextBlock Width="100" Text="{Binding Path=Element[{http://planetsNS}DiameterKM].Value}" />
<TextBlock Width="100" Text="{Binding Path=Attribute[Name].Value}" />
<TextBlock Text="{Binding Path=Element[{http://planetsNS}Details].Value}" />
<TextBlock Text="{Binding Source={x:Static system:DateTime.Now}, StringFormat=Date: {0:dddd, MMMM dd}}" />
<TextBlock Text="{Binding Source={x:Static system:DateTime.Now}, StringFormat=Time: {0:HH:mm}}" />
</StackPanel>
</DataTemplate>
</StackPanel.Resources>
<TextBlock Text="{Binding Path=ActualWidth, StringFormat=Window width: {0:#,#.0}}" />
<TextBlock Text="{Binding Path=ActualHeight, StringFormat=Window height: {0:C}}" />
<WrapPanel Margin="10">
<TextBlock Text="Width: " />
<TextBlock Text="{Binding ActualWidth, StringFormat={}{0:#,#.0}}" />
<StackPanel Margin="10">
<TextBlock Text="{Binding Source={x:Static system:DateTime.Now}, ConverterCulture=de-DE, StringFormat=German date: {0:D}}" />
<TextBlock Text="{Binding Source={x:Static system:DateTime.Now}, ConverterCulture=en-US, StringFormat=American date: {0:D}}" />
<TextBlock Text="{Binding Source={x:Static system:DateTime.Now}, ConverterCulture=ja-JP, StringFormat=Japanese date: {0:D}}" />
</StackPanel>
</WrapPanel>
</StackPanel>
</UserControl>
2 changes: 1 addition & 1 deletion ILSpy.BamlDecompiler/Tests/Cases/MarkupExtension.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<Style />
</Label.Style>
<Label.Content>
<Binding Path="Blah" />
<Binding Path="Blah" StringFormat="{}{0} items" />
</Label.Content>
</Label>
1 change: 1 addition & 0 deletions ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Style />
</cc:CustomControl.Style>
<Grid.Row>0</Grid.Row>
<cc:CustomControl.Tag>{}{Test}</cc:CustomControl.Tag>
<cc:CustomControl.CustomName>Custom1</cc:CustomControl.CustomName>
</cc:CustomControl>
<Label ToolTip="{DynamicResource {x:Static cc:CustomControl.SimpleProperty}}">
Expand Down
13 changes: 8 additions & 5 deletions ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@
<Name>ILSpy.BamlDecompiler</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Cases" />
<Folder Include="Mocks" />
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Cases\AttachedEvent.xaml" />
<Page Include="Cases\AvalonDockBrushes.xaml" />
<Page Include="Cases\AvalonDockCommon.xaml" />
<Page Include="Cases\EscapeSequence.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\MarkupExtension.xaml" />
<Page Include="Cases\MyControl.xaml" />
<Page Include="Cases\NamespacePrefix.xaml" />
Expand All @@ -139,5 +139,8 @@
<Page Include="Cases\Dictionary1.xaml" />
<Page Include="Cases\Issue445.xaml" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
6 changes: 6 additions & 0 deletions ILSpy.BamlDecompiler/Tests/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public void NamespacePrefix()
{
RunTest("cases/namespaceprefix");
}

[Test]
public void EscapeSequence()
{
RunTest("cases/escapesequence");
}

#region RunTest
void RunTest(string name)
Expand Down

0 comments on commit 0ada95d

Please sign in to comment.