Skip to content

Commit 332aaab

Browse files
committed
No repro for #354
Keeping the tests any way
1 parent a92bf8b commit 332aaab

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

  • WpfAnalyzers.Test/WPF0010DefaultValueMustMatchRegisteredTypeTests

WpfAnalyzers.Test/WPF0010DefaultValueMustMatchRegisteredTypeTests/Valid.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,5 +630,74 @@ public enum FooEnum
630630
RoslynAssert.Valid(Analyzer, enumCode, fooCode, code);
631631
RoslynAssert.Valid(Analyzer, enumCode, code, fooCode);
632632
}
633+
634+
[Test]
635+
public static void SubTypeIssue354Simple()
636+
{
637+
var code = @"
638+
namespace ValidCode.Repro
639+
{
640+
using System.Windows;
641+
using System.Windows.Controls;
642+
using System.Windows.Media;
643+
644+
public class C : Image
645+
{
646+
public static readonly DependencyProperty IconGeometryProperty = DependencyProperty.Register(
647+
nameof(IconGeometry),
648+
typeof(Geometry),
649+
typeof(C),
650+
new PropertyMetadata(new EllipseGeometry(default, 5, 5)));
651+
652+
public Geometry IconGeometry
653+
{
654+
get => (Geometry)GetValue(IconGeometryProperty);
655+
set => SetValue(IconGeometryProperty, value);
656+
}
657+
}
658+
}";
659+
660+
RoslynAssert.Valid(Analyzer, Descriptors.WPF0010DefaultValueMustMatchRegisteredType, code);
661+
}
662+
663+
[Test]
664+
public static void SubTypeIssue354()
665+
{
666+
var code = @"
667+
namespace ValidCode.Repro
668+
{
669+
using System.Windows;
670+
using System.Windows.Controls;
671+
using System.Windows.Media;
672+
673+
public class TypeA : Image
674+
{
675+
public Geometry IconGeometry
676+
{
677+
get => (Geometry)GetValue(IconGeometryProperty);
678+
set => SetValue(IconGeometryProperty, value);
679+
}
680+
681+
public static readonly DependencyProperty IconGeometryProperty =
682+
DependencyProperty.Register(nameof(IconGeometry), typeof(Geometry), typeof(TypeA), new PropertyMetadata(null));
683+
}
684+
685+
public class TypeB : Image
686+
{
687+
public Geometry IconGeometry
688+
{
689+
get => (Geometry)GetValue(IconGeometryProperty);
690+
// WPF0014 SetValue must use registered type System.Windows.Media.Geometry
691+
set => SetValue(IconGeometryProperty, value);
692+
}
693+
694+
public static readonly DependencyProperty IconGeometryProperty =
695+
// WPF0010 Default value for 'TypeA.IconGeometryProperty' must be of type System.Windows.Media.Geometry
696+
TypeA.IconGeometryProperty.AddOwner(typeof(TypeB), new FrameworkPropertyMetadata(new EllipseGeometry(default, 5, 5)));
697+
}
698+
}";
699+
700+
RoslynAssert.Valid(Analyzer, Descriptors.WPF0010DefaultValueMustMatchRegisteredType, code);
701+
}
633702
}
634703
}

0 commit comments

Comments
 (0)