Browse Source

fix #470: BAML to XAML conversion does not generate escape sequence {} correctly

pull/512/head
Siegfried Pammer 11 years ago
parent
commit
0ada95d913
  1. 5
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 13
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  3. 26
      ILSpy.BamlDecompiler/Tests/Cases/EscapeSequence.xaml
  4. 2
      ILSpy.BamlDecompiler/Tests/Cases/MarkupExtension.xaml
  5. 1
      ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml
  6. 13
      ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj
  7. 6
      ILSpy.BamlDecompiler/Tests/TestRunner.cs

5
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -127,11 +127,12 @@ @@ -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>

13
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -908,7 +908,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -908,7 +908,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
short identifier = reader.ReadInt16();
string text = reader.ReadString();
EnqueueProperty(identifier, text);
EnqueueProperty(identifier, EscapeCurlyBraces(text));
}
void ReadPropertyWithConverter()
@ -917,7 +917,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -917,7 +917,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
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()

26
ILSpy.BamlDecompiler/Tests/Cases/EscapeSequence.xaml

@ -0,0 +1,26 @@ @@ -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
ILSpy.BamlDecompiler/Tests/Cases/MarkupExtension.xaml

@ -3,6 +3,6 @@ @@ -3,6 +3,6 @@
<Style />
</Label.Style>
<Label.Content>
<Binding Path="Blah" />
<Binding Path="Blah" StringFormat="{}{0} items" />
</Label.Content>
</Label>

1
ILSpy.BamlDecompiler/Tests/Cases/NamespacePrefix.xaml

@ -4,6 +4,7 @@ @@ -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}}">

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

@ -117,15 +117,15 @@ @@ -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" />
@ -139,5 +139,8 @@ @@ -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
ILSpy.BamlDecompiler/Tests/TestRunner.cs

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

Loading…
Cancel
Save