Browse Source

Fix #1547: Fully qualify attached properties in styles.

pull/1556/head
Siegfried Pammer 7 years ago
parent
commit
d965e6aa9e
  1. 4
      ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs
  2. 6
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  3. 4
      ILSpy.BamlDecompiler.Tests/Cases/AvalonDockCommon.xaml
  4. 24
      ILSpy.BamlDecompiler.Tests/Cases/Issue1547.xaml
  5. 27
      ILSpy.BamlDecompiler.Tests/Cases/Issue1547.xaml.cs
  6. 4
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  7. 2325
      ILSpy.BamlDecompiler/Baml/test.cs
  8. 14
      ILSpy.BamlDecompiler/Handlers/Records/PropertyCustomHandler.cs
  9. 15
      ILSpy.BamlDecompiler/Handlers/Records/PropertyTypeReferenceHandler.cs

4
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -521,9 +521,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
return SpecialType.UnknownType; return SpecialType.UnknownType;
} }
public static bool FullNameIs(this IMethod method, string type, string name) public static bool FullNameIs(this IMember member, string type, string name)
{ {
return method.Name == name && method.DeclaringType?.FullName == type; return member.Name == name && member.DeclaringType?.FullName == type;
} }
public static KnownAttribute IsBuiltinAttribute(this ITypeDefinition type) public static KnownAttribute IsBuiltinAttribute(this ITypeDefinition type)

6
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

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

4
ILSpy.BamlDecompiler.Tests/Cases/AvalonDockCommon.xaml

@ -35,8 +35,8 @@
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True"> <Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter TargetName="PaneHeaderCommandIntBorder" Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.PaneHeaderCommandBorderBrush}}}" /> <Setter TargetName="PaneHeaderCommandIntBorder" Property="Border.BorderBrush" Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.PaneHeaderCommandBorderBrush}}}" />
<Setter TargetName="PaneHeaderCommandIntBorder" Property="Background" Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.PaneHeaderCommandBackground}}}" /> <Setter TargetName="PaneHeaderCommandIntBorder" Property="Border.Background" Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.PaneHeaderCommandBackground}}}" />
<Setter TargetName="PaneHeaderCommandIntBorder" Property="UIElement.Opacity" Value="1" /> <Setter TargetName="PaneHeaderCommandIntBorder" Property="UIElement.Opacity" Value="1" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>

24
ILSpy.BamlDecompiler.Tests/Cases/Issue1547.xaml

@ -0,0 +1,24 @@
<Window x:Class="ILSpy.BamlDecompiler.Tests.Cases.Issue1547" 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="Issue1547" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button>
<FrameworkElement.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Grid.Row" Value="1" />
<Setter Property="Content" Value="World!" />
</Style>
</FrameworkElement.Style>
</Button>
<Button>
<FrameworkElement.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Grid.Row" Value="0" />
<Setter Property="Content" Value="Hello" />
</Style>
</FrameworkElement.Style>
</Button>
</Grid>
</Window>

27
ILSpy.BamlDecompiler.Tests/Cases/Issue1547.xaml.cs

@ -0,0 +1,27 @@
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 Issue1547.xaml
/// </summary>
public partial class Issue1547 : Window
{
public Issue1547()
{
InitializeComponent();
}
}
}

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

@ -47,6 +47,7 @@
<DependentUpon>AttachedEvent.xaml</DependentUpon> <DependentUpon>AttachedEvent.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Cases\CustomControl.cs" /> <Compile Include="Cases\CustomControl.cs" />
<Compile Include="Cases\Issue1547.xaml.cs" />
<Compile Include="Cases\MyControl.xaml.cs"> <Compile Include="Cases\MyControl.xaml.cs">
<DependentUpon>MyControl.xaml</DependentUpon> <DependentUpon>MyControl.xaml</DependentUpon>
</Compile> </Compile>
@ -77,6 +78,9 @@
<Page Include="Cases\Issue1546.xaml"> <Page Include="Cases\Issue1546.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Cases\Issue1547.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Issue775.xaml"> <Page Include="Cases\Issue775.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>

2325
ILSpy.BamlDecompiler/Baml/test.cs

File diff suppressed because it is too large Load Diff

14
ILSpy.BamlDecompiler/Handlers/Records/PropertyCustomHandler.cs

@ -47,7 +47,7 @@ namespace ILSpy.BamlDecompiler.Handlers {
case KnownTypes.DependencyPropertyConverter: { case KnownTypes.DependencyPropertyConverter: {
if (value.Length == 2) { if (value.Length == 2) {
var property = ctx.ResolveProperty(reader.ReadUInt16()); var property = ctx.ResolveProperty(reader.ReadUInt16());
return ctx.ToString(elem, property.ToXName(ctx, elem, false)); return ctx.ToString(elem, property.ToXName(ctx, elem, NeedsFullName(property, ctx, elem)));
} }
else { else {
var type = ctx.ResolveType(reader.ReadUInt16()); var type = ctx.ResolveType(reader.ReadUInt16());
@ -142,6 +142,18 @@ namespace ILSpy.BamlDecompiler.Handlers {
throw new NotSupportedException(ser.ToString()); throw new NotSupportedException(ser.ToString());
} }
private bool NeedsFullName(XamlProperty property, XamlContext ctx, XElement elem)
{
XElement p = elem.Parent;
while (p != null && p.Annotation<XamlType>()?.ResolvedType.FullName != "System.Windows.Style") {
p = p.Parent;
}
var type = p?.Annotation<TargetTypeAnnotation>()?.Type;
if (type == null)
return true;
return property.IsAttachedTo(type);
}
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
var record = (PropertyCustomRecord)((BamlRecordNode)node).Record; var record = (PropertyCustomRecord)((BamlRecordNode)node).Record;
var serTypeId = ((short)record.SerializerTypeId & 0xfff); var serTypeId = ((short)record.SerializerTypeId & 0xfff);

15
ILSpy.BamlDecompiler/Handlers/Records/PropertyTypeReferenceHandler.cs

@ -23,6 +23,7 @@
using System.Xml.Linq; using System.Xml.Linq;
using ILSpy.BamlDecompiler.Baml; using ILSpy.BamlDecompiler.Baml;
using ILSpy.BamlDecompiler.Xaml; using ILSpy.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.TypeSystem;
namespace ILSpy.BamlDecompiler.Handlers { namespace ILSpy.BamlDecompiler.Handlers {
internal class PropertyTypeReferenceHandler : IHandler { internal class PropertyTypeReferenceHandler : IHandler {
@ -39,6 +40,10 @@ namespace ILSpy.BamlDecompiler.Handlers {
var elemAttr = ctx.ResolveProperty(record.AttributeId); var elemAttr = ctx.ResolveProperty(record.AttributeId);
elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null));
if (attr.ResolvedMember.FullNameIs("System.Windows.Style", "TargetType")) {
parent.Xaml.Element.AddAnnotation(new TargetTypeAnnotation(type));
}
elem.Xaml.Element.AddAnnotation(elemAttr); elem.Xaml.Element.AddAnnotation(elemAttr);
parent.Xaml.Element.Add(elem.Xaml.Element); parent.Xaml.Element.Add(elem.Xaml.Element);
@ -53,4 +58,14 @@ namespace ILSpy.BamlDecompiler.Handlers {
return elem; return elem;
} }
} }
internal class TargetTypeAnnotation
{
public XamlType Type { get; }
public TargetTypeAnnotation(XamlType type)
{
this.Type = type;
}
}
} }
Loading…
Cancel
Save