Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 968bdc0

Browse files
Enable Nullability on Xamarin.CommunityToolkit.Markup (#1013)
* Enable Nullable on Unit Tests * Enable Nullable on Xamarin.CommunityToolkit.Markup
1 parent 8a74608 commit 968bdc0

9 files changed

+161
-152
lines changed

src/Markup/Xamarin.CommunityToolkit.Markup/BindableObjectExtensions.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public static TBindable Bind<TBindable>(
1313
BindableProperty targetProperty,
1414
string path = bindingContextPath,
1515
BindingMode mode = BindingMode.Default,
16-
IValueConverter converter = null,
17-
object converterParameter = null,
18-
string stringFormat = null,
19-
object source = null,
20-
object targetNullValue = null,
21-
object fallbackValue = null) where TBindable : BindableObject
16+
IValueConverter? converter = null,
17+
object? converterParameter = null,
18+
string? stringFormat = null,
19+
object? source = null,
20+
object? targetNullValue = null,
21+
object? fallbackValue = null) where TBindable : BindableObject
2222
{
2323
bindable.SetBinding(
2424
targetProperty,
@@ -36,12 +36,12 @@ public static TBindable Bind<TBindable, TSource, TDest>(
3636
BindableProperty targetProperty,
3737
string path = bindingContextPath,
3838
BindingMode mode = BindingMode.Default,
39-
Func<TSource, TDest> convert = null,
40-
Func<TDest, TSource> convertBack = null,
41-
string stringFormat = null,
42-
object source = null,
43-
TDest targetNullValue = default,
44-
TDest fallbackValue = default) where TBindable : BindableObject
39+
Func<TSource?, TDest>? convert = null,
40+
Func<TDest?, TSource>? convertBack = null,
41+
string? stringFormat = null,
42+
object? source = null,
43+
TDest? targetNullValue = default,
44+
TDest? fallbackValue = default) where TBindable : BindableObject
4545
{
4646
var converter = new FuncConverter<TSource, TDest, object>(convert, convertBack);
4747
bindable.SetBinding(
@@ -60,13 +60,13 @@ public static TBindable Bind<TBindable, TSource, TParam, TDest>(
6060
BindableProperty targetProperty,
6161
string path = bindingContextPath,
6262
BindingMode mode = BindingMode.Default,
63-
Func<TSource, TParam, TDest> convert = null,
64-
Func<TDest, TParam, TSource> convertBack = null,
65-
TParam converterParameter = default,
66-
string stringFormat = null,
67-
object source = null,
68-
TDest targetNullValue = default,
69-
TDest fallbackValue = default) where TBindable : BindableObject
63+
Func<TSource?, TParam?, TDest>? convert = null,
64+
Func<TDest?, TParam?, TSource>? convertBack = null,
65+
TParam? converterParameter = default,
66+
string? stringFormat = null,
67+
object? source = null,
68+
TDest? targetNullValue = default,
69+
TDest? fallbackValue = default) where TBindable : BindableObject
7070
{
7171
var converter = new FuncConverter<TSource, TDest, TParam>(convert, convertBack);
7272
bindable.SetBinding(
@@ -84,12 +84,12 @@ public static TBindable Bind<TBindable>(
8484
this TBindable bindable,
8585
string path = bindingContextPath,
8686
BindingMode mode = BindingMode.Default,
87-
IValueConverter converter = null,
88-
object converterParameter = null,
89-
string stringFormat = null,
90-
object source = null,
91-
object targetNullValue = null,
92-
object fallbackValue = null) where TBindable : BindableObject
87+
IValueConverter? converter = null,
88+
object? converterParameter = null,
89+
string? stringFormat = null,
90+
object? source = null,
91+
object? targetNullValue = null,
92+
object? fallbackValue = null) where TBindable : BindableObject
9393
{
9494
bindable.Bind(
9595
DefaultBindableProperties.GetFor(bindable),
@@ -102,12 +102,12 @@ public static TBindable Bind<TBindable, TSource, TDest>(
102102
this TBindable bindable,
103103
string path = bindingContextPath,
104104
BindingMode mode = BindingMode.Default,
105-
Func<TSource, TDest> convert = null,
106-
Func<TDest, TSource> convertBack = null,
107-
string stringFormat = null,
108-
object source = null,
109-
TDest targetNullValue = default,
110-
TDest fallbackValue = default) where TBindable : BindableObject
105+
Func<TSource?, TDest>? convert = null,
106+
Func<TDest?, TSource>? convertBack = null,
107+
string? stringFormat = null,
108+
object? source = null,
109+
TDest? targetNullValue = default,
110+
TDest? fallbackValue = default) where TBindable : BindableObject
111111
{
112112
var converter = new FuncConverter<TSource, TDest, object>(convert, convertBack);
113113
bindable.Bind(
@@ -121,13 +121,13 @@ public static TBindable Bind<TBindable, TSource, TParam, TDest>(
121121
this TBindable bindable,
122122
string path = bindingContextPath,
123123
BindingMode mode = BindingMode.Default,
124-
Func<TSource, TParam, TDest> convert = null,
125-
Func<TDest, TParam, TSource> convertBack = null,
126-
TParam converterParameter = default,
127-
string stringFormat = null,
128-
object source = null,
129-
TDest targetNullValue = default,
130-
TDest fallbackValue = default) where TBindable : BindableObject
124+
Func<TSource?, TParam?, TDest>? convert = null,
125+
Func<TDest?, TParam?, TSource>? convertBack = null,
126+
TParam? converterParameter = default,
127+
string? stringFormat = null,
128+
object? source = null,
129+
TDest? targetNullValue = default,
130+
TDest? fallbackValue = default) where TBindable : BindableObject
131131
{
132132
var converter = new FuncConverter<TSource, TDest, TParam>(convert, convertBack);
133133
bindable.Bind(
@@ -141,9 +141,9 @@ public static TBindable Bind<TBindable, TSource, TParam, TDest>(
141141
public static TBindable BindCommand<TBindable>(
142142
this TBindable bindable,
143143
string path = bindingContextPath,
144-
object source = null,
145-
string parameterPath = bindingContextPath,
146-
object parameterSource = null) where TBindable : BindableObject
144+
object? source = null,
145+
string? parameterPath = bindingContextPath,
146+
object? parameterSource = null) where TBindable : BindableObject
147147
{
148148
(var commandProperty, var parameterProperty) = DefaultBindableProperties.GetForCommand(bindable);
149149

src/Markup/Xamarin.CommunityToolkit.Markup/BindableObjectMultiBindExtensions.cs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TDest>(
1212
BindableProperty targetProperty,
1313
BindingBase binding1,
1414
BindingBase binding2,
15-
Func<ValueTuple<TSource1, TSource2>, TDest> convert = null,
16-
Func<TDest, ValueTuple<TSource1, TSource2>> convertBack = null,
15+
Func<ValueTuple<TSource1?, TSource2?>, TDest>? convert = null,
16+
Func<TDest?, ValueTuple<TSource1, TSource2>>? convertBack = null,
1717
BindingMode mode = BindingMode.Default,
18-
string stringFormat = null,
19-
TDest targetNullValue = default,
20-
TDest fallbackValue = default) where TBindable : BindableObject
18+
string? stringFormat = null,
19+
TDest? targetNullValue = default,
20+
TDest? fallbackValue = default) where TBindable : BindableObject
2121
=> bindable.Bind(
2222
targetProperty,
2323
new List<BindingBase> { binding1, binding2 },
@@ -34,13 +34,13 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TParam, TDest>(
3434
BindableProperty targetProperty,
3535
BindingBase binding1,
3636
BindingBase binding2,
37-
Func<ValueTuple<TSource1, TSource2>, TParam, TDest> convert = null,
38-
Func<TDest, TParam, ValueTuple<TSource1, TSource2>> convertBack = null,
39-
TParam converterParameter = default,
37+
Func<ValueTuple<TSource1?, TSource2?>, TParam?, TDest>? convert = null,
38+
Func<TDest?, TParam?, ValueTuple<TSource1, TSource2>>? convertBack = null,
39+
TParam? converterParameter = default,
4040
BindingMode mode = BindingMode.Default,
41-
string stringFormat = null,
42-
TDest targetNullValue = default,
43-
TDest fallbackValue = default) where TBindable : BindableObject
41+
string? stringFormat = null,
42+
TDest? targetNullValue = default,
43+
TDest? fallbackValue = default) where TBindable : BindableObject
4444
=> bindable.Bind(
4545
targetProperty,
4646
new List<BindingBase> { binding1, binding2 },
@@ -58,12 +58,12 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TSource3, TDest>(
5858
BindingBase binding1,
5959
BindingBase binding2,
6060
BindingBase binding3,
61-
Func<ValueTuple<TSource1, TSource2, TSource3>, TDest> convert = null,
62-
Func<TDest, ValueTuple<TSource1, TSource2, TSource3>> convertBack = null,
61+
Func<ValueTuple<TSource1?, TSource2?, TSource3?>, TDest>? convert = null,
62+
Func<TDest?, ValueTuple<TSource1, TSource2, TSource3>>? convertBack = null,
6363
BindingMode mode = BindingMode.Default,
64-
string stringFormat = null,
65-
TDest targetNullValue = default,
66-
TDest fallbackValue = default) where TBindable : BindableObject
64+
string? stringFormat = null,
65+
TDest? targetNullValue = default,
66+
TDest? fallbackValue = default) where TBindable : BindableObject
6767
=> bindable.Bind(
6868
targetProperty,
6969
new List<BindingBase> { binding1, binding2, binding3 },
@@ -81,13 +81,13 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TSource3, TParam, TD
8181
BindingBase binding1,
8282
BindingBase binding2,
8383
BindingBase binding3,
84-
Func<ValueTuple<TSource1, TSource2, TSource3>, TParam, TDest> convert = null,
85-
Func<TDest, TParam, ValueTuple<TSource1, TSource2, TSource3>> convertBack = null,
86-
TParam converterParameter = default,
84+
Func<ValueTuple<TSource1?, TSource2?, TSource3?>, TParam?, TDest>? convert = null,
85+
Func<TDest?, TParam?, ValueTuple<TSource1, TSource2, TSource3>>? convertBack = null,
86+
TParam? converterParameter = default,
8787
BindingMode mode = BindingMode.Default,
88-
string stringFormat = null,
89-
TDest targetNullValue = default,
90-
TDest fallbackValue = default) where TBindable : BindableObject
88+
string? stringFormat = null,
89+
TDest? targetNullValue = default,
90+
TDest? fallbackValue = default) where TBindable : BindableObject
9191
=> bindable.Bind(
9292
targetProperty,
9393
new List<BindingBase> { binding1, binding2, binding3 },
@@ -106,12 +106,12 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TSource3, TSource4,
106106
BindingBase binding2,
107107
BindingBase binding3,
108108
BindingBase binding4,
109-
Func<ValueTuple<TSource1, TSource2, TSource3, TSource4>, TDest> convert = null,
110-
Func<TDest, ValueTuple<TSource1, TSource2, TSource3, TSource4>> convertBack = null,
109+
Func<ValueTuple<TSource1?, TSource2?, TSource3?, TSource4?>, TDest>? convert = null,
110+
Func<TDest?, ValueTuple<TSource1, TSource2, TSource3, TSource4>>? convertBack = null,
111111
BindingMode mode = BindingMode.Default,
112-
string stringFormat = null,
113-
TDest targetNullValue = default,
114-
TDest fallbackValue = default) where TBindable : BindableObject
112+
string? stringFormat = null,
113+
TDest? targetNullValue = default,
114+
TDest? fallbackValue = default) where TBindable : BindableObject
115115
=> bindable.Bind(
116116
targetProperty,
117117
new List<BindingBase> { binding1, binding2, binding3, binding4 },
@@ -130,13 +130,13 @@ public static TBindable Bind<TBindable, TSource1, TSource2, TSource3, TSource4,
130130
BindingBase binding2,
131131
BindingBase binding3,
132132
BindingBase binding4,
133-
Func<ValueTuple<TSource1, TSource2, TSource3, TSource4>, TParam, TDest> convert = null,
134-
Func<TDest, TParam, ValueTuple<TSource1, TSource2, TSource3, TSource4>> convertBack = null,
135-
TParam converterParameter = default,
133+
Func<ValueTuple<TSource1?, TSource2?, TSource3?, TSource4?>, TParam?, TDest>? convert = null,
134+
Func<TDest?, TParam?, ValueTuple<TSource1, TSource2, TSource3, TSource4>>? convertBack = null,
135+
TParam? converterParameter = default,
136136
BindingMode mode = BindingMode.Default,
137-
string stringFormat = null,
138-
TDest targetNullValue = default,
139-
TDest fallbackValue = default) where TBindable : BindableObject
137+
string? stringFormat = null,
138+
TDest? targetNullValue = default,
139+
TDest? fallbackValue = default) where TBindable : BindableObject
140140
=> bindable.Bind(
141141
targetProperty,
142142
new List<BindingBase> { binding1, binding2, binding3, binding4 },
@@ -153,11 +153,11 @@ public static TBindable Bind<TBindable>(
153153
BindableProperty targetProperty,
154154
IList<BindingBase> bindings,
155155
IMultiValueConverter converter,
156-
object converterParameter = default,
156+
object? converterParameter = default,
157157
BindingMode mode = BindingMode.Default,
158-
string stringFormat = null,
159-
object targetNullValue = null,
160-
object fallbackValue = null) where TBindable : BindableObject
158+
string? stringFormat = null,
159+
object? targetNullValue = null,
160+
object? fallbackValue = null) where TBindable : BindableObject
161161
{
162162
bindable.SetBinding(targetProperty, new MultiBinding
163163
{

src/Markup/Xamarin.CommunityToolkit.Markup/ElementExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static TElement RemoveDynamicResources<TElement>(this TElement element, p
4141

4242
public static TElement Effects<TElement>(this TElement element, params Effect[] effects) where TElement : Element
4343
{
44-
for (int i = 0; i < effects.Length; i++)
44+
for (var i = 0; i < effects.Length; i++)
4545
element.Effects.Add(effects[i]);
4646
return element;
4747
}
@@ -59,7 +59,7 @@ public static TFontElement Italic<TFontElement>(this TFontElement fontElement) w
5959

6060
public static TFontElement Font<TFontElement>(
6161
this TFontElement fontElement,
62-
string family = null,
62+
string? family = null,
6363
double? size = null,
6464
bool? bold = null,
6565
bool? italic = null) where TFontElement : Element, IFontElement

src/Markup/Xamarin.CommunityToolkit.Markup/ElementGesturesExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public static class ElementGesturesExtensions
1313
public static TGestureElement BindClickGesture<TGestureElement>(
1414
this TGestureElement gestureElement,
1515
string commandPath = bindingContextPath,
16-
object commandSource = null,
17-
string parameterPath = null,
18-
object parameterSource = null) where TGestureElement : Element, IGestureRecognizers
16+
object? commandSource = null,
17+
string? parameterPath = null,
18+
object? parameterSource = null) where TGestureElement : Element, IGestureRecognizers
1919
=> ClickGesture(gestureElement, g => g.BindCommand(commandPath, commandSource, parameterPath, parameterSource));
2020

2121
/// <summary>Add a <see cref="SwipeGestureRecognizer"/>,
@@ -24,9 +24,9 @@ public static TGestureElement BindClickGesture<TGestureElement>(
2424
public static TGestureElement BindSwipeGesture<TGestureElement>(
2525
this TGestureElement gestureElement,
2626
string commandPath = bindingContextPath,
27-
object commandSource = null,
28-
string parameterPath = null,
29-
object parameterSource = null) where TGestureElement : Element, IGestureRecognizers
27+
object? commandSource = null,
28+
string? parameterPath = null,
29+
object? parameterSource = null) where TGestureElement : Element, IGestureRecognizers
3030
=> SwipeGesture(gestureElement, g => g.BindCommand(commandPath, commandSource, parameterPath, parameterSource));
3131

3232
/// <summary>Add a <see cref="TapGestureRecognizer"/>,
@@ -35,9 +35,9 @@ public static TGestureElement BindSwipeGesture<TGestureElement>(
3535
public static TGestureElement BindTapGesture<TGestureElement>(
3636
this TGestureElement gestureElement,
3737
string commandPath = bindingContextPath,
38-
object commandSource = null,
39-
string parameterPath = null,
40-
object parameterSource = null) where TGestureElement : Element, IGestureRecognizers
38+
object? commandSource = null,
39+
string? parameterPath = null,
40+
object? parameterSource = null) where TGestureElement : Element, IGestureRecognizers
4141
=> TapGesture(gestureElement, g => g.BindCommand(commandPath, commandSource, parameterPath, parameterSource));
4242

4343
/// <summary>Add a <see cref="ClickGestureRecognizer"/>,

src/Markup/Xamarin.CommunityToolkit.Markup/FuncConverter.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ namespace Xamarin.CommunityToolkit.Markup
66
{
77
public class FuncConverter<TSource, TDest, TParam> : IValueConverter
88
{
9-
readonly Func<TSource, TDest> convert;
10-
readonly Func<TDest, TSource> convertBack;
9+
readonly Func<TSource?, TDest>? convert;
10+
readonly Func<TDest?, TSource>? convertBack;
1111

12-
readonly Func<TSource, TParam, TDest> convertWithParam;
13-
readonly Func<TDest, TParam, TSource> convertBackWithParam;
12+
readonly Func<TSource?, TParam?, TDest>? convertWithParam;
13+
readonly Func<TDest?, TParam?, TSource>? convertBackWithParam;
1414

15-
readonly Func<TSource, TParam, CultureInfo, TDest> convertWithParamAndCulture;
16-
readonly Func<TDest, TParam, CultureInfo, TSource> convertBackWithParamAndCulture;
15+
readonly Func<TSource?, TParam?, CultureInfo, TDest>? convertWithParamAndCulture;
16+
readonly Func<TDest?, TParam?, CultureInfo, TSource>? convertBackWithParamAndCulture;
1717

18-
public FuncConverter(Func<TSource, TParam, CultureInfo, TDest> convertWithParamAndCulture = null, Func<TDest, TParam, CultureInfo, TSource> convertBackWithParamAndCulture = null)
18+
public FuncConverter(Func<TSource?, TParam?, CultureInfo, TDest>? convertWithParamAndCulture = null, Func<TDest?, TParam?, CultureInfo, TSource>? convertBackWithParamAndCulture = null)
1919
{ this.convertWithParamAndCulture = convertWithParamAndCulture; this.convertBackWithParamAndCulture = convertBackWithParamAndCulture; }
2020

21-
public FuncConverter(Func<TSource, TParam, TDest> convertWithParam = null, Func<TDest, TParam, TSource> convertBackWithParam = null)
21+
public FuncConverter(Func<TSource?, TParam?, TDest>? convertWithParam = null, Func<TDest?, TParam?, TSource>? convertBackWithParam = null)
2222
{ this.convertWithParam = convertWithParam; this.convertBackWithParam = convertBackWithParam; }
2323

24-
public FuncConverter(Func<TSource, TDest> convert = null, Func<TDest, TSource> convertBack = null)
24+
public FuncConverter(Func<TSource?, TDest>? convert = null, Func<TDest?, TSource>? convertBack = null)
2525
{ this.convert = convert; this.convertBack = convertBack; }
2626

27-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
27+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
2828
{
2929
if (convert != null)
3030
{
@@ -50,7 +50,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
5050
return default(TDest);
5151
}
5252

53-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
53+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
5454
{
5555
if (convertBack != null)
5656
{
@@ -79,19 +79,19 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
7979

8080
public class FuncConverter<TSource, TDest> : FuncConverter<TSource, TDest, object>
8181
{
82-
public FuncConverter(Func<TSource, TDest> convert = null, Func<TDest, TSource> convertBack = null)
82+
public FuncConverter(Func<TSource?, TDest>? convert = null, Func<TDest?, TSource>? convertBack = null)
8383
: base(convert, convertBack) { }
8484
}
8585

8686
public class FuncConverter<TSource> : FuncConverter<TSource, object, object>
8787
{
88-
public FuncConverter(Func<TSource, object> convert = null, Func<object, TSource> convertBack = null)
88+
public FuncConverter(Func<TSource?, object>? convert = null, Func<object?, TSource>? convertBack = null)
8989
: base(convert, convertBack) { }
9090
}
9191

9292
public class FuncConverter : FuncConverter<object, object, object>
9393
{
94-
public FuncConverter(Func<object, object> convert = null, Func<object, object> convertBack = null)
94+
public FuncConverter(Func<object?, object>? convert = null, Func<object?, object>? convertBack = null)
9595
: base(convert, convertBack) { }
9696
}
9797

0 commit comments

Comments
 (0)