88using Microsoft . CodeAnalysis . CSharp ;
99using Microsoft . CodeAnalysis . Testing ;
1010using Microsoft . VisualStudio . TestTools . UnitTesting ;
11+ using Windows . Foundation ;
1112using Windows . UI . ViewManagement ;
1213using Windows . UI . Xaml ;
1314using CSharpCodeFixTest = CommunityToolkit . GeneratedDependencyProperty . Tests . Helpers . CSharpCodeFixTest <
@@ -25,7 +26,41 @@ public class Test_UseGeneratedDependencyPropertyOnManualPropertyCodeFixer
2526 [ DataRow ( "object" , "object" ) ]
2627 [ DataRow ( "object" , "object?" ) ]
2728 [ DataRow ( "int" , "int" ) ]
29+ [ DataRow ( "byte" , "byte" ) ]
30+ [ DataRow ( "sbyte" , "sbyte" ) ]
31+ [ DataRow ( "short" , "short" ) ]
32+ [ DataRow ( "ushort" , "ushort" ) ]
33+ [ DataRow ( "uint" , "uint" ) ]
34+ [ DataRow ( "long" , "long" ) ]
35+ [ DataRow ( "ulong" , "ulong" ) ]
36+ [ DataRow ( "char" , "char" ) ]
37+ [ DataRow ( "float" , "float" ) ]
38+ [ DataRow ( "double" , "double" ) ]
39+ [ DataRow ( "global::System.Numerics.Matrix3x2" , "global::System.Numerics.Matrix3x2" ) ]
40+ [ DataRow ( "global::System.Numerics.Matrix4x4" , "global::System.Numerics.Matrix4x4" ) ]
41+ [ DataRow ( "global::System.Numerics.Plane" , "global::System.Numerics.Plane" ) ]
42+ [ DataRow ( "global::System.Numerics.Quaternion" , "global::System.Numerics.Quaternion" ) ]
43+ [ DataRow ( "global::System.Numerics.Vector2" , "global::System.Numerics.Vector2" ) ]
44+ [ DataRow ( "global::System.Numerics.Vector3" , "global::System.Numerics.Vector3" ) ]
45+ [ DataRow ( "global::System.Numerics.Vector4" , "global::System.Numerics.Vector4" ) ]
46+ [ DataRow ( "global::Windows.Foundation.Point" , "global::Windows.Foundation.Point" ) ]
47+ [ DataRow ( "global::Windows.Foundation.Rect" , "global::Windows.Foundation.Rect" ) ]
48+ [ DataRow ( "global::Windows.Foundation.Size" , "global::Windows.Foundation.Size" ) ]
49+ [ DataRow ( "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility" ) ]
2850 [ DataRow ( "int?" , "int?" ) ]
51+ [ DataRow ( "byte?" , "byte?" ) ]
52+ [ DataRow ( "char?" , "char?" ) ]
53+ [ DataRow ( "long?" , "long?" ) ]
54+ [ DataRow ( "float?" , "float?" ) ]
55+ [ DataRow ( "double?" , "double?" ) ]
56+ [ DataRow ( "global::System.DateTimeOffset?" , "global::System.DateTimeOffset?" ) ]
57+ [ DataRow ( "global::System.TimeSpan?" , "global::System.TimeSpan?" ) ]
58+ [ DataRow ( "global::System.Guid?" , "global::System.Guid?" ) ]
59+ [ DataRow ( "global::System.Collections.Generic.KeyValuePair<int, float>?" , "global::System.Collections.Generic.KeyValuePair<int, float>?" ) ]
60+ [ DataRow ( "global::MyApp.MyStruct" , "global::MyApp.MyStruct" ) ]
61+ [ DataRow ( "global::MyApp.MyStruct?" , "global::MyApp.MyStruct?" ) ]
62+ [ DataRow ( "global::MyApp.MyEnum" , "global::MyApp.MyEnum" ) ]
63+ [ DataRow ( "global::MyApp.MyEnum?" , "global::MyApp.MyEnum?" ) ]
2964 public async Task SimpleProperty ( string dependencyPropertyType , string propertyType )
3065 {
3166 string original = $$ """
@@ -48,6 +83,9 @@ public class MyControl : Control
4883 set => SetValue(NameProperty, value);
4984 }
5085 }
86+
87+ public struct MyStruct { public string X { get; set; } }
88+ public enum MyEnum { A, B, C }
5189 """ ;
5290
5391 string @fixed = $$ """
@@ -62,6 +100,9 @@ public partial class MyControl : Control
62100 [GeneratedDependencyProperty]
63101 public partial {{ propertyType }} {|CS9248:Name|} { get; set; }
64102 }
103+
104+ public struct MyStruct { public string X { get; set; } }
105+ public enum MyEnum { A, B, C }
65106 """ ;
66107
67108 CSharpCodeFixTest test = new ( LanguageVersion . Preview )
@@ -71,6 +112,7 @@ public partial class MyControl : Control
71112 ReferenceAssemblies = ReferenceAssemblies . Net . Net80 ,
72113 TestState = { AdditionalReferences =
73114 {
115+ MetadataReference . CreateFromFile ( typeof ( Point ) . Assembly . Location ) ,
74116 MetadataReference . CreateFromFile ( typeof ( ApplicationView ) . Assembly . Location ) ,
75117 MetadataReference . CreateFromFile ( typeof ( DependencyProperty ) . Assembly . Location ) ,
76118 MetadataReference . CreateFromFile ( typeof ( GeneratedDependencyPropertyAttribute ) . Assembly . Location )
@@ -93,6 +135,23 @@ public partial class MyControl : Control
93135 [ DataRow ( "int?" , "int?" , "default(int?)" ) ]
94136 [ DataRow ( "int?" , "int?" , "null" ) ]
95137 [ DataRow ( "System.TimeSpan" , "System.TimeSpan" , "default(System.TimeSpan)" ) ]
138+ [ DataRow ( "global::System.Numerics.Matrix3x2" , "global::System.Numerics.Matrix3x2" , "default(global::System.Numerics.Matrix3x2)" ) ]
139+ [ DataRow ( "global::System.Numerics.Matrix4x4" , "global::System.Numerics.Matrix4x4" , "default(global::System.Numerics.Matrix4x4)" ) ]
140+ [ DataRow ( "global::System.Numerics.Plane" , "global::System.Numerics.Plane" , "default(global::System.Numerics.Plane)" ) ]
141+ [ DataRow ( "global::System.Numerics.Quaternion" , "global::System.Numerics.Quaternion" , "default(global::System.Numerics.Quaternion)" ) ]
142+ [ DataRow ( "global::System.Numerics.Vector2" , "global::System.Numerics.Vector2" , "default(global::System.Numerics.Vector2)" ) ]
143+ [ DataRow ( "global::System.Numerics.Vector3" , "global::System.Numerics.Vector3" , "default(global::System.Numerics.Vector3)" ) ]
144+ [ DataRow ( "global::System.Numerics.Vector4" , "global::System.Numerics.Vector4" , "default(global::System.Numerics.Vector4)" ) ]
145+ [ DataRow ( "global::Windows.Foundation.Point" , "global::Windows.Foundation.Point" , "default(global::Windows.Foundation.Point)" ) ]
146+ [ DataRow ( "global::Windows.Foundation.Rect" , "global::Windows.Foundation.Rect" , "default(global::Windows.Foundation.Rect)" ) ]
147+ [ DataRow ( "global::Windows.Foundation.Size" , "global::Windows.Foundation.Size" , "default(global::Windows.Foundation.Size)" ) ]
148+ [ DataRow ( "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility" , "default(global::Windows.UI.Xaml.Visibility)" ) ]
149+ [ DataRow ( "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility.Visible" ) ]
150+ [ DataRow ( "global::System.DateTimeOffset?" , "global::System.DateTimeOffset?" , "default(global::System.DateTimeOffset?)" ) ]
151+ [ DataRow ( "global::System.DateTimeOffset?" , "global::System.DateTimeOffset?" , "null" ) ]
152+ [ DataRow ( "global::System.TimeSpan?" , "global::System.TimeSpan?" , "null" ) ]
153+ [ DataRow ( "global::System.Guid?" , "global::System.Guid?" , "null" ) ]
154+ [ DataRow ( "global::System.Collections.Generic.KeyValuePair<int, float>?" , "global::System.Collections.Generic.KeyValuePair<int, float>?" , "null" ) ]
96155 public async Task SimpleProperty_WithExplicitValue_DefaultValue (
97156 string dependencyPropertyType ,
98157 string propertyType ,
@@ -145,6 +204,7 @@ public partial class MyControl : Control
145204 ReferenceAssemblies = ReferenceAssemblies . Net . Net80 ,
146205 TestState = { AdditionalReferences =
147206 {
207+ MetadataReference . CreateFromFile ( typeof ( Point ) . Assembly . Location ) ,
148208 MetadataReference . CreateFromFile ( typeof ( ApplicationView ) . Assembly . Location ) ,
149209 MetadataReference . CreateFromFile ( typeof ( DependencyProperty ) . Assembly . Location ) ,
150210 MetadataReference . CreateFromFile ( typeof ( GeneratedDependencyPropertyAttribute ) . Assembly . Location )
@@ -160,6 +220,7 @@ public partial class MyControl : Control
160220 [ DataRow ( "int" , "int" , "42" ) ]
161221 [ DataRow ( "int?" , "int?" , "0" ) ]
162222 [ DataRow ( "int?" , "int?" , "42" ) ]
223+ [ DataRow ( "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility" , "global::Windows.UI.Xaml.Visibility.Collapsed" ) ]
163224 public async Task SimpleProperty_WithExplicitValue_NotDefault (
164225 string dependencyPropertyType ,
165226 string propertyType ,
@@ -212,6 +273,7 @@ public partial class MyControl : Control
212273 ReferenceAssemblies = ReferenceAssemblies . Net . Net80 ,
213274 TestState = { AdditionalReferences =
214275 {
276+ MetadataReference . CreateFromFile ( typeof ( Point ) . Assembly . Location ) ,
215277 MetadataReference . CreateFromFile ( typeof ( ApplicationView ) . Assembly . Location ) ,
216278 MetadataReference . CreateFromFile ( typeof ( DependencyProperty ) . Assembly . Location ) ,
217279 MetadataReference . CreateFromFile ( typeof ( GeneratedDependencyPropertyAttribute ) . Assembly . Location )
0 commit comments