Skip to content

Commit 76d5e01

Browse files
committed
refactor: add nullable annotations to improve code safety and clarity
1 parent 8fa999c commit 76d5e01

38 files changed

Lines changed: 70 additions & 61 deletions

src/MADE.Collections/CollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static bool Update<T>(this IList<T> collection, T item, Func<T, T, bool>
7878
ArgumentNullException.ThrowIfNull(item);
7979
ArgumentNullException.ThrowIfNull(collection);
8080

81-
T existing = collection.FirstOrDefault(x => predicate.Invoke(x, item));
81+
T? existing = collection.FirstOrDefault(x => predicate.Invoke(x, item));
8282
if (existing == null)
8383
{
8484
return false;

src/MADE.Collections/ObjectModel/ObservableItemCollection{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public ObservableItemCollection(List<T> list)
8383
/// <summary>
8484
/// Occurs when an item is added, removed, changed, moved, or the entire list is refreshed.
8585
/// </summary>
86-
public override event NotifyCollectionChangedEventHandler CollectionChanged;
86+
public override event NotifyCollectionChangedEventHandler? CollectionChanged;
8787

8888
/// <summary>
8989
/// Occurs when an item's <see cref="INotifyPropertyChanged.PropertyChanged"/> event is invoked.
9090
/// </summary>
91-
public event ObservableItemCollectionPropertyChangedEventHandler ItemPropertyChanged;
91+
public event ObservableItemCollectionPropertyChangedEventHandler? ItemPropertyChanged;
9292

9393
/// <summary>
9494
/// Adds a range of objects to the end of the collection.

src/MADE.Data.Converters/BooleanToStringValueConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class BooleanToStringValueConverter : IValueConverter<bool, string>
1414
/// <summary>
1515
/// Gets or sets the positive/true value.
1616
/// </summary>
17-
public string TrueValue { get; set; }
17+
public string TrueValue { get; set; } = string.Empty;
1818

1919
/// <summary>
2020
/// Gets or sets the negative/false value.
2121
/// </summary>
22-
public string FalseValue { get; set; }
22+
public string FalseValue { get; set; } = string.Empty;
2323

2424
/// <summary>
2525
/// Converts the <paramref name="value">value</paramref> to the <see cref="string"/> type.
@@ -33,7 +33,7 @@ public class BooleanToStringValueConverter : IValueConverter<bool, string>
3333
/// <returns>
3434
/// The converted <see cref="string"/> object.
3535
/// </returns>
36-
public string Convert(bool value, object parameter = default)
36+
public string Convert(bool value, object? parameter = default)
3737
{
3838
return value.ToFormattedString(this.TrueValue, this.FalseValue);
3939
}
@@ -50,7 +50,7 @@ public string Convert(bool value, object parameter = default)
5050
/// <returns>
5151
/// The converted <see cref="bool"/> object.
5252
/// </returns>
53-
public bool ConvertBack(string value, object parameter = default)
53+
public bool ConvertBack(string value, object? parameter = default)
5454
{
5555
if (value == this.TrueValue)
5656
{

src/MADE.Data.Converters/DateTimeToStringValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DateTimeToStringValueConverter : IValueConverter<DateTime, string>
2323
/// <returns>
2424
/// The converted <see cref="string"/> object.
2525
/// </returns>
26-
public string Convert(DateTime value, object parameter = default)
26+
public string Convert(DateTime value, object? parameter = default)
2727
{
2828
string format = parameter?.ToString();
2929
return !string.IsNullOrWhiteSpace(format)
@@ -43,7 +43,7 @@ public string Convert(DateTime value, object parameter = default)
4343
/// <returns>
4444
/// The converted <see cref="DateTime"/> object.
4545
/// </returns>
46-
public DateTime ConvertBack(string value, object parameter = default)
46+
public DateTime ConvertBack(string value, object? parameter = default)
4747
{
4848
if (string.IsNullOrWhiteSpace(value))
4949
{

src/MADE.Data.Converters/IValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface IValueConverter<TFrom, TTo>
2626
/// <returns>
2727
/// The converted <typeparamref name="TTo"/> object.
2828
/// </returns>
29-
TTo Convert(TFrom value, object parameter = default);
29+
TTo Convert(TFrom value, object? parameter = default);
3030

3131
/// <summary>
3232
/// Converts the <paramref name="value">value</paramref> back to the <typeparamref name="TFrom"/> type.
@@ -40,5 +40,5 @@ public interface IValueConverter<TFrom, TTo>
4040
/// <returns>
4141
/// The converted <typeparamref name="TFrom"/> object.
4242
/// </returns>
43-
TFrom ConvertBack(TTo value, object parameter = default);
43+
TFrom ConvertBack(TTo value, object? parameter = default);
4444
}

src/MADE.Data.Converters/StringToBase64StringValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public partial class StringToBase64StringValueConverter : IValueConverter<string
2323
/// <returns>
2424
/// The converted Base64 <see cref="string"/> object.
2525
/// </returns>
26-
public string Convert(string value, object parameter = default)
26+
public string Convert(string value, object? parameter = default)
2727
{
2828
return value.ToBase64(parameter as Encoding ?? Encoding.UTF8);
2929
}
@@ -40,7 +40,7 @@ public string Convert(string value, object parameter = default)
4040
/// <returns>
4141
/// The converted <see cref="string"/> object.
4242
/// </returns>
43-
public string ConvertBack(string value, object parameter = default)
43+
public string ConvertBack(string value, object? parameter = default)
4444
{
4545
return value.FromBase64(parameter as Encoding ?? Encoding.UTF8);
4646
}

src/MADE.Data.Validation.FluentValidation/FluentValidatorCollection{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public FluentValidatorCollection(int capacity)
4040
/// <summary>
4141
/// Occurs when the input value is validated against the collection of validators.
4242
/// </summary>
43-
public event InputValidatedEventHandler Validated;
43+
public event InputValidatedEventHandler? Validated;
4444

4545
/// <summary>
4646
/// Gets or sets a value indicating whether the data provided is in an invalid state.

src/MADE.Data.Validation/ValidatorCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ValidatorCollection(int capacity)
3838
/// <summary>
3939
/// Occurs when the input value is validated against the collection of validators.
4040
/// </summary>
41-
public event InputValidatedEventHandler Validated;
41+
public event InputValidatedEventHandler? Validated;
4242

4343
/// <summary>
4444
/// Gets or sets a value indicating whether the data provided is in an invalid state.

src/MADE.Data.Validation/Validators/AlphaNumericValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MADE.Data.Validation.Validators;
1111
/// </summary>
1212
public class AlphaNumericValidator : RegexValidator
1313
{
14-
private string feedbackMessage;
14+
private string feedbackMessage = string.Empty;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="AlphaNumericValidator"/> class with the expected RegEx pattern.

src/MADE.Data.Validation/Validators/AlphaValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MADE.Data.Validation.Validators;
1111
/// </summary>
1212
public class AlphaValidator : RegexValidator
1313
{
14-
private string feedbackMessage;
14+
private string feedbackMessage = string.Empty;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="AlphaValidator"/> class with the expected RegEx pattern.

0 commit comments

Comments
 (0)