Browse Source

Fix #2097: Prefix:PropertyName is invalid syntax

pull/2113/head
Siegfried Pammer 5 years ago
parent
commit
e0a8f957cc
  1. 6
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  2. 5
      ILSpy.BamlDecompiler.Tests/Cases/Issue2097.xaml
  3. 32
      ILSpy.BamlDecompiler.Tests/Cases/Issue2097.xaml.cs
  4. 4
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  5. 4
      ILSpy.BamlDecompiler/Xaml/XamlProperty.cs
  6. 11
      ILSpy.BamlDecompiler/Xaml/XamlUtils.cs

6
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

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

5
ILSpy.BamlDecompiler.Tests/Cases/Issue2097.xaml

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<Window x:Class="ILSpy.BamlDecompiler.Tests.Cases.Issue2097" 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases" Title="{x:Static local:Issue2097Temp.Test}" Height="450" Width="800">
<Grid>
<TextBlock Text="{x:Static local:Issue2097Temp.Test}" />
</Grid>
</Window>

32
ILSpy.BamlDecompiler.Tests/Cases/Issue2097.xaml.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace ILSpy.BamlDecompiler.Tests.Cases
{
/// <summary>
/// Interaction logic for Issue2097.xaml
/// </summary>
public partial class Issue2097 : Window
{
public Issue2097()
{
InitializeComponent();
}
}
class Issue2097Temp
{
public static string Test = "Hello";
}
}

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

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

4
ILSpy.BamlDecompiler/Xaml/XamlProperty.cs

@ -82,9 +82,7 @@ namespace ILSpy.BamlDecompiler.Xaml { @@ -82,9 +82,7 @@ namespace ILSpy.BamlDecompiler.Xaml {
name = XmlConvert.EncodeLocalName(PropertyName);
else {
name = typeName.LocalName + "." + XmlConvert.EncodeLocalName(PropertyName);
if (parent == null || (parent.GetDefaultNamespace() != typeName.Namespace
&& parent.Name.Namespace != typeName.Namespace))
if (parent == null || parent.GetDefaultNamespace() != typeName.Namespace)
name = typeName.Namespace + name.LocalName;
}

11
ILSpy.BamlDecompiler/Xaml/XamlUtils.cs

@ -41,11 +41,12 @@ namespace ILSpy.BamlDecompiler.Xaml { @@ -41,11 +41,12 @@ namespace ILSpy.BamlDecompiler.Xaml {
public static string ToString(this XamlContext ctx, XElement elem, XName name) {
var sb = new StringBuilder();
if (name.Namespace != elem.GetDefaultNamespace() &&
name.Namespace != elem.Name.Namespace &&
!string.IsNullOrEmpty(name.Namespace.NamespaceName)) {
sb.Append(elem.GetPrefixOfNamespace(name.Namespace));
sb.Append(':');
if (name.Namespace != elem.GetDefaultNamespace()) {
var prefix = elem.GetPrefixOfNamespace(name.Namespace);
if (!string.IsNullOrEmpty(prefix)) {
sb.Append(prefix);
sb.Append(':');
}
}
sb.Append(name.LocalName);
return sb.ToString();

Loading…
Cancel
Save