Skip to content

Commit 5521734

Browse files
[Net 10] - Annotated remaining Converter classes for nullability - 2 (#30777)
* Annotated converters * fixed missing API * more changes * further refactoring * more changes
1 parent 8a2f830 commit 5521734

File tree

14 files changed

+301
-39
lines changed

14 files changed

+301
-39
lines changed

src/Controls/src/Core/Items/CarouselLayoutTypeConverter.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
using System;
32
using System.ComponentModel;
43
using System.Globalization;
@@ -8,35 +7,45 @@ namespace Microsoft.Maui.Controls
87
/// <include file="../../../docs/Microsoft.Maui.Controls/CarouselLayoutTypeConverter.xml" path="Type[@FullName='Microsoft.Maui.Controls.CarouselLayoutTypeConverter']/Docs/*" />
98
public class CarouselLayoutTypeConverter : TypeConverter
109
{
11-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
10+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1211
=> sourceType == typeof(string);
1312

14-
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
13+
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
1514
=> destinationType == typeof(string);
1615

17-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
16+
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
1817
{
1918
var strValue = value?.ToString();
2019

2120
if (strValue == "HorizontalList")
21+
{
2222
return LinearItemsLayout.CarouselDefault;
23+
}
2324

2425
if (strValue == "VerticalList")
26+
{
2527
return LinearItemsLayout.CarouselVertical;
28+
}
2629

2730
throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(LinearItemsLayout)}");
2831
}
2932

30-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
33+
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
3134
{
3235
if (value is not LinearItemsLayout lil)
36+
{
3337
throw new NotSupportedException();
38+
}
3439

3540
if (lil == LinearItemsLayout.CarouselDefault)
41+
{
3642
return "HorizontalList";
43+
}
3744

3845
if (lil == LinearItemsLayout.CarouselVertical)
46+
{
3947
return "VerticalList";
48+
}
4049

4150
throw new NotSupportedException();
4251
}

src/Controls/src/Core/Items/ItemsLayoutTypeConverter.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
using System;
32
using System.ComponentModel;
43
using System.Globalization;
@@ -8,25 +7,31 @@ namespace Microsoft.Maui.Controls
87
/// <include file="../../../docs/Microsoft.Maui.Controls/ItemsLayoutTypeConverter.xml" path="Type[@FullName='Microsoft.Maui.Controls.ItemsLayoutTypeConverter']/Docs/*" />
98
public class ItemsLayoutTypeConverter : TypeConverter
109
{
11-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
10+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1211
=> sourceType == typeof(string);
1312

14-
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
13+
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
1514
=> destinationType == typeof(string);
1615

17-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
16+
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
1817
{
1918
var strValue = value?.ToString();
20-
if (strValue == null)
19+
if (strValue is null)
20+
{
2121
throw new ArgumentNullException(nameof(strValue));
22+
}
2223

2324
ItemsLayoutOrientation? orientation = default(ItemsLayoutOrientation?);
2425
int identifierLength = 0;
2526

2627
if (strValue == "VerticalList")
28+
{
2729
return LinearItemsLayout.Vertical;
30+
}
2831
else if (strValue == "HorizontalList")
32+
{
2933
return LinearItemsLayout.Horizontal;
34+
}
3035
else if (strValue.StartsWith("VerticalGrid", StringComparison.Ordinal))
3136
{
3237
orientation = ItemsLayoutOrientation.Vertical;
@@ -41,7 +46,9 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
4146
if (orientation.HasValue)
4247
{
4348
if (strValue.Length == identifierLength)
49+
{
4450
return new GridItemsLayout(orientation.Value);
51+
}
4552
else if (strValue.Length > identifierLength + 1 && strValue[identifierLength] == ',')
4653
{
4754
var argument = strValue.Substring(identifierLength + 1);
@@ -53,14 +60,23 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
5360
throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(IItemsLayout)}");
5461
}
5562

56-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
63+
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
5764
{
5865
if (value is LinearItemsLayout && value == LinearItemsLayout.Vertical)
66+
{
5967
return "VerticalList";
68+
}
69+
6070
if (value is LinearItemsLayout && value == LinearItemsLayout.Horizontal)
71+
{
6172
return "HorizontalList";
73+
}
74+
6275
if (value is GridItemsLayout gil)
76+
{
6377
return $"{gil.Orientation}Grid,{gil.Span}";
78+
}
79+
6480
throw new NotSupportedException();
6581
}
6682
}

src/Controls/src/Core/Layout/BoundsTypeConverter.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
using System;
32
using System.ComponentModel;
43
using System.Globalization;
@@ -10,18 +9,18 @@ namespace Microsoft.Maui.Controls
109
[Xaml.ProvideCompiled("Microsoft.Maui.Controls.XamlC.BoundsTypeConverter")]
1110
public sealed class BoundsTypeConverter : TypeConverter
1211
{
13-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
12+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1413
=> sourceType == typeof(string);
1514

16-
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
15+
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
1716
=> destinationType == typeof(string);
1817

19-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
18+
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
2019
{
2120
// IMPORTANT! Update BoundsDesignTypeConverter.IsValid if making changes here
2221
var strValue = value?.ToString();
2322

24-
if (strValue != null)
23+
if (strValue is not null)
2524
{
2625
double x = -1, y = -1, w = -1, h = -1;
2726
string[] xywh = strValue.Split(',');
@@ -45,18 +44,26 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
4544
}
4645

4746
if (hasX && hasY && xywh.Length == 2)
47+
{
4848
return new Rect(x, y, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize);
49+
}
50+
4951
if (hasX && hasY && hasW && hasH && xywh.Length == 4)
52+
{
5053
return new Rect(x, y, w, h);
54+
}
5155
}
5256

5357
throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rect)}");
5458
}
5559

56-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
60+
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
5761
{
5862
if (value is not Rect rect)
63+
{
5964
throw new NotSupportedException();
65+
}
66+
6067
return $"{rect.X.ToString(CultureInfo.InvariantCulture)}, {rect.Y.ToString(CultureInfo.InvariantCulture)}, {(rect.Width == AbsoluteLayout.AutoSize ? nameof(AbsoluteLayout.AutoSize) : rect.Width.ToString(CultureInfo.InvariantCulture))}, {(rect.Height == AbsoluteLayout.AutoSize ? nameof(AbsoluteLayout.AutoSize) : rect.Height.ToString(CultureInfo.InvariantCulture))}";
6168
}
6269
}

src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ override Microsoft.Maui.Controls.BrushTypeConverter.CanConvertFrom(System.Compon
192192
override Microsoft.Maui.Controls.BrushTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
193193
override Microsoft.Maui.Controls.BrushTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
194194
override Microsoft.Maui.Controls.BrushTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
195+
override Microsoft.Maui.Controls.BoundsTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
196+
override Microsoft.Maui.Controls.BoundsTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
197+
override Microsoft.Maui.Controls.BoundsTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
198+
override Microsoft.Maui.Controls.BoundsTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
199+
override Microsoft.Maui.Controls.CarouselLayoutTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
200+
override Microsoft.Maui.Controls.CarouselLayoutTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
201+
override Microsoft.Maui.Controls.CarouselLayoutTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
202+
override Microsoft.Maui.Controls.CarouselLayoutTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
195203
override Microsoft.Maui.Controls.ColumnDefinitionCollectionTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
196204
override Microsoft.Maui.Controls.ColumnDefinitionCollectionTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
197205
override Microsoft.Maui.Controls.ColumnDefinitionCollectionTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
@@ -235,6 +243,10 @@ override Microsoft.Maui.Controls.ImageSourceConverter.CanConvertFrom(System.Comp
235243
override Microsoft.Maui.Controls.ImageSourceConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
236244
override Microsoft.Maui.Controls.ImageSourceConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
237245
override Microsoft.Maui.Controls.ImageSourceConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
246+
override Microsoft.Maui.Controls.ItemsLayoutTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
247+
override Microsoft.Maui.Controls.ItemsLayoutTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
248+
override Microsoft.Maui.Controls.ItemsLayoutTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
249+
override Microsoft.Maui.Controls.ItemsLayoutTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
238250
override Microsoft.Maui.Controls.LayoutOptionsConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
239251
override Microsoft.Maui.Controls.LayoutOptionsConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
240252
override Microsoft.Maui.Controls.LayoutOptionsConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
@@ -266,6 +278,10 @@ override Microsoft.Maui.Controls.ShadowTypeConverter.CanConvertFrom(System.Compo
266278
override Microsoft.Maui.Controls.ShadowTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
267279
override Microsoft.Maui.Controls.ShadowTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object!
268280
override Microsoft.Maui.Controls.ShadowTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type? destinationType) -> object!
281+
override Microsoft.Maui.Controls.WebViewSourceTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
282+
override Microsoft.Maui.Controls.WebViewSourceTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
283+
override Microsoft.Maui.Controls.WebViewSourceTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
284+
override Microsoft.Maui.Controls.WebViewSourceTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
269285
override Microsoft.Maui.Controls.Shapes.MatrixTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
270286
override Microsoft.Maui.Controls.Shapes.MatrixTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
271287
override Microsoft.Maui.Controls.Shapes.MatrixTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
@@ -278,6 +294,14 @@ override Microsoft.Maui.Controls.Shapes.PathGeometryConverter.CanConvertFrom(Sys
278294
override Microsoft.Maui.Controls.Shapes.PathGeometryConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
279295
override Microsoft.Maui.Controls.Shapes.PathGeometryConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
280296
override Microsoft.Maui.Controls.Shapes.PathGeometryConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
297+
override Microsoft.Maui.Controls.Shapes.PointCollectionConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
298+
override Microsoft.Maui.Controls.Shapes.PointCollectionConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
299+
override Microsoft.Maui.Controls.Shapes.PointCollectionConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
300+
override Microsoft.Maui.Controls.Shapes.PointCollectionConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
301+
override Microsoft.Maui.Controls.Shapes.TransformTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
302+
override Microsoft.Maui.Controls.Shapes.TransformTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
303+
override Microsoft.Maui.Controls.Shapes.TransformTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
304+
override Microsoft.Maui.Controls.Shapes.TransformTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
281305
~override Microsoft.Maui.Controls.StackLayout.ComputeConstraintForView(Microsoft.Maui.Controls.View view) -> void
282306
~override Microsoft.Maui.Controls.TemplatedPage.ComputeConstraintForView(Microsoft.Maui.Controls.View view) -> void
283307
~override Microsoft.Maui.Controls.TemplatedView.ComputeConstraintForView(Microsoft.Maui.Controls.View view) -> void
@@ -295,6 +319,10 @@ override Microsoft.Maui.Controls.TypeTypeConverter.CanConvertFrom(System.Compone
295319
override Microsoft.Maui.Controls.TypeTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
296320
override Microsoft.Maui.Controls.TypeTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
297321
override Microsoft.Maui.Controls.TypeTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
322+
override Microsoft.Maui.Controls.UriTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
323+
override Microsoft.Maui.Controls.UriTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
324+
override Microsoft.Maui.Controls.UriTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
325+
override Microsoft.Maui.Controls.UriTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
298326
~override Microsoft.Maui.Controls.VerticalStackLayout.ComputeConstraintForView(Microsoft.Maui.Controls.View view) -> void
299327
*REMOVED*~static Microsoft.Maui.Controls.Accelerator.FromString(string text) -> Microsoft.Maui.Controls.Accelerator
300328
*REMOVED*~static Microsoft.Maui.Controls.Accelerator.implicit operator Microsoft.Maui.Controls.Accelerator(string accelerator) -> Microsoft.Maui.Controls.Accelerator

0 commit comments

Comments
 (0)