Skip to content

Commit 4e6bea6

Browse files
committed
More attempts at repro #354
1 parent 332aaab commit 4e6bea6

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

  • WpfAnalyzers.Test
    • WPF0010DefaultValueMustMatchRegisteredTypeTests
    • WPF0014SetValueMustUseRegisteredTypeTests

WpfAnalyzers.Test/WPF0010DefaultValueMustMatchRegisteredTypeTests/Valid.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ public Geometry IconGeometry
663663
[Test]
664664
public static void SubTypeIssue354()
665665
{
666-
var code = @"
666+
var typeA = @"
667667
namespace ValidCode.Repro
668668
{
669669
using System.Windows;
@@ -680,7 +680,15 @@ public Geometry IconGeometry
680680
681681
public static readonly DependencyProperty IconGeometryProperty =
682682
DependencyProperty.Register(nameof(IconGeometry), typeof(Geometry), typeof(TypeA), new PropertyMetadata(null));
683-
}
683+
}
684+
}";
685+
686+
var typeB = @"
687+
namespace ValidCode.Repro
688+
{
689+
using System.Windows;
690+
using System.Windows.Controls;
691+
using System.Windows.Media;
684692
685693
public class TypeB : Image
686694
{
@@ -697,7 +705,7 @@ public Geometry IconGeometry
697705
}
698706
}";
699707

700-
RoslynAssert.Valid(Analyzer, Descriptors.WPF0010DefaultValueMustMatchRegisteredType, code);
708+
RoslynAssert.Valid(Analyzer, Descriptors.WPF0010DefaultValueMustMatchRegisteredType, typeA, typeB);
701709
}
702710
}
703711
}

WpfAnalyzers.Test/WPF0014SetValueMustUseRegisteredTypeTests/Valid.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,5 +1091,53 @@ public void M(Issue278 control, Color? color = null)
10911091

10921092
RoslynAssert.Valid(Analyzer, code);
10931093
}
1094+
1095+
[Test]
1096+
public static void SubTypeIssue354()
1097+
{
1098+
var typeA = @"
1099+
namespace ValidCode.Repro
1100+
{
1101+
using System.Windows;
1102+
using System.Windows.Controls;
1103+
using System.Windows.Media;
1104+
1105+
public class TypeA : Image
1106+
{
1107+
public Geometry IconGeometry
1108+
{
1109+
get => (Geometry)GetValue(IconGeometryProperty);
1110+
set => SetValue(IconGeometryProperty, value);
1111+
}
1112+
1113+
public static readonly DependencyProperty IconGeometryProperty =
1114+
DependencyProperty.Register(nameof(IconGeometry), typeof(Geometry), typeof(TypeA), new PropertyMetadata(null));
1115+
}
1116+
}";
1117+
1118+
var typeB = @"
1119+
namespace ValidCode.Repro
1120+
{
1121+
using System.Windows;
1122+
using System.Windows.Controls;
1123+
using System.Windows.Media;
1124+
1125+
public class TypeB : Image
1126+
{
1127+
public Geometry IconGeometry
1128+
{
1129+
get => (Geometry)GetValue(IconGeometryProperty);
1130+
// WPF0014 SetValue must use registered type System.Windows.Media.Geometry
1131+
set => SetValue(IconGeometryProperty, value);
1132+
}
1133+
1134+
public static readonly DependencyProperty IconGeometryProperty =
1135+
// WPF0010 Default value for 'TypeA.IconGeometryProperty' must be of type System.Windows.Media.Geometry
1136+
TypeA.IconGeometryProperty.AddOwner(typeof(TypeB), new FrameworkPropertyMetadata(new EllipseGeometry(default, 5, 5)));
1137+
}
1138+
}";
1139+
1140+
RoslynAssert.Valid(Analyzer, typeA, typeB);
1141+
}
10941142
}
10951143
}

0 commit comments

Comments
 (0)