Skip to content

Commit 1422dd0

Browse files
committed
Remove nullable disable from converters
1 parent bd96955 commit 1422dd0

12 files changed

Lines changed: 37 additions & 37 deletions

src/ImageSharp.Web/Commands/CommandCollection.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Web.Commands;
1010
/// <summary>
1111
/// Represents an ordered collection of processing commands.
1212
/// </summary>
13-
public sealed class CommandCollection : KeyedCollection<string, KeyValuePair<string, string>>
13+
public sealed class CommandCollection : KeyedCollection<string, KeyValuePair<string, string?>>
1414
{
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="CommandCollection"/> class.
@@ -32,7 +32,7 @@ public IEnumerable<string> Keys
3232
{
3333
get
3434
{
35-
foreach (KeyValuePair<string, string> item in this)
35+
foreach (KeyValuePair<string, string?> item in this)
3636
{
3737
yield return this.GetKeyForItem(item);
3838
}
@@ -64,7 +64,7 @@ public IEnumerable<string> Keys
6464

6565
set
6666
{
67-
if (this.TryGetValue(key, out KeyValuePair<string, string> item))
67+
if (this.TryGetValue(key, out KeyValuePair<string, string?> item))
6868
{
6969
this.SetItem(this.IndexOf(item), new(key, value));
7070
}
@@ -109,10 +109,10 @@ public IEnumerable<string> Keys
109109
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
110110
public bool TryGetValue(string key, [NotNullWhen(true)] out string? value)
111111
{
112-
if (this.TryGetValue(key, out KeyValuePair<string, string> keyValue))
112+
if (this.TryGetValue(key, out KeyValuePair<string, string?> keyValue))
113113
{
114114
value = keyValue.Value;
115-
return true;
115+
return value is not null;
116116
}
117117

118118
value = default;
@@ -138,7 +138,7 @@ public int FindIndex(Predicate<string> match)
138138
Guard.NotNull(match, nameof(match));
139139

140140
int index = 0;
141-
foreach (KeyValuePair<string, string> item in this)
141+
foreach (KeyValuePair<string, string?> item in this)
142142
{
143143
if (match(item.Key))
144144
{
@@ -162,7 +162,7 @@ public int FindIndex(Predicate<string> match)
162162
/// </returns>
163163
public int IndexOf(string key)
164164
{
165-
if (this.TryGetValue(key, out KeyValuePair<string, string> item))
165+
if (this.TryGetValue(key, out KeyValuePair<string, string?> item))
166166
{
167167
return this.IndexOf(item);
168168
}
@@ -172,7 +172,7 @@ public int IndexOf(string key)
172172

173173
/// <inheritdoc/>
174174
[MethodImpl(MethodImplOptions.AggressiveInlining)]
175-
protected override string GetKeyForItem(KeyValuePair<string, string> item) => item.Key;
175+
protected override string GetKeyForItem(KeyValuePair<string, string?> item) => item.Key;
176176

177177
[MethodImpl(MethodImplOptions.NoInlining)]
178178
[DoesNotReturn]

src/ImageSharp.Web/Commands/CommandCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static class CommandCollectionExtensions
1414
/// <param name="collection">The collection instance.</param>
1515
/// <param name="key">The key of the value to get.</param>
1616
/// <returns>The value associated with the specified key or the default value.</returns>
17-
public static string GetValueOrDefault(this CommandCollection collection, string key)
17+
public static string? GetValueOrDefault(this CommandCollection collection, string key)
1818
{
19-
collection.TryGetValue(key, out KeyValuePair<string, string> result);
19+
collection.TryGetValue(key, out KeyValuePair<string, string?> result);
2020
return result.Value;
2121
}
2222
}

src/ImageSharp.Web/Commands/CommandParser.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Globalization;
56
using System.Net;
67
using System.Runtime.CompilerServices;
@@ -35,7 +36,7 @@ public CommandParser(IEnumerable<ICommandConverter> converters)
3536
/// </typeparam>
3637
/// <returns>The converted instance or the default.</returns>
3738
[MethodImpl(MethodImplOptions.AggressiveInlining)]
38-
public T? ParseValue<T>(string value, CultureInfo culture)
39+
public T? ParseValue<T>(string? value, CultureInfo culture)
3940
{
4041
DebugGuard.NotNull(culture, nameof(culture));
4142

@@ -58,7 +59,7 @@ public CommandParser(IEnumerable<ICommandConverter> converters)
5859
converter = Array.Find(this.converters, x => x.Type.Equals(typeof(Enum)));
5960
if (converter != null)
6061
{
61-
return (T)((ICommandConverter<object>)converter).ConvertFrom(
62+
return (T?)((ICommandConverter<object>)converter).ConvertFrom(
6263
this,
6364
culture,
6465
WebUtility.UrlDecode(value),
@@ -73,6 +74,7 @@ public CommandParser(IEnumerable<ICommandConverter> converters)
7374
}
7475

7576
[MethodImpl(MethodImplOptions.NoInlining)]
77+
[DoesNotReturn]
7678
private static void ThrowNotSupported(Type type)
7779
=> throw new NotSupportedException($"Cannot convert to {type.FullName}.");
7880
}

src/ImageSharp.Web/Commands/Converters/ArrayConverter{T}.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Runtime.CompilerServices;
@@ -21,7 +20,7 @@ public sealed class ArrayConverter<T> : ICommandConverter<T[]>
2120
public T[] ConvertFrom(
2221
CommandParser parser,
2322
CultureInfo culture,
24-
string value,
23+
string? value,
2524
Type propertyType)
2625
{
2726
if (string.IsNullOrWhiteSpace(value))
@@ -32,7 +31,7 @@ public T[] ConvertFrom(
3231
var result = new List<T>();
3332
foreach (string pill in GetStringArray(value, culture))
3433
{
35-
T item = parser.ParseValue<T>(pill, culture);
34+
T? item = parser.ParseValue<T>(pill, culture);
3635
if (item != null)
3736
{
3837
result.Add(item);

src/ImageSharp.Web/Commands/Converters/ColorConverter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Reflection;
@@ -35,7 +34,7 @@ public sealed class ColorConverter : ICommandConverter<Color>
3534

3635
/// <inheritdoc/>
3736
[MethodImpl(MethodImplOptions.AggressiveInlining)]
38-
public Color ConvertFrom(CommandParser parser, CultureInfo culture, string value, Type propertyType)
37+
public Color ConvertFrom(CommandParser parser, CultureInfo culture, string? value, Type propertyType)
3938
{
4039
if (string.IsNullOrWhiteSpace(value))
4140
{
@@ -60,9 +59,9 @@ public Color ConvertFrom(CommandParser parser, CultureInfo culture, string value
6059

6160
if (convert)
6261
{
63-
List<byte> rgba = parser.ParseValue<List<byte>>(value, culture);
62+
List<byte>? rgba = parser.ParseValue<List<byte>>(value, culture);
6463

65-
return rgba.Count switch
64+
return rgba?.Count switch
6665
{
6766
4 => Color.FromRgba(rgba[0], rgba[1], rgba[2], rgba[3]),
6867
3 => Color.FromRgb(rgba[0], rgba[1], rgba[2]),
@@ -90,7 +89,7 @@ private static IDictionary<string, Color> InitializeColorConstantsTable()
9089
{
9190
if (field.FieldType == typeof(Color))
9291
{
93-
table[field.Name] = (Color)field.GetValue(null);
92+
table[field.Name] = (Color)field.GetValue(null)!;
9493
}
9594
}
9695

src/ImageSharp.Web/Commands/Converters/EnumConverter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Runtime.CompilerServices;
@@ -22,10 +21,10 @@ public sealed class EnumConverter : ICommandConverter<object>
2221
/// This allows us to reuse the same converter for infinite enum types.
2322
/// </remarks>
2423
[MethodImpl(MethodImplOptions.NoInlining)]
25-
public object ConvertFrom(
24+
public object? ConvertFrom(
2625
CommandParser parser,
2726
CultureInfo culture,
28-
string value,
27+
string? value,
2928
Type propertyType)
3029
{
3130
if (string.IsNullOrWhiteSpace(value))

src/ImageSharp.Web/Commands/Converters/ICommandConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65

@@ -35,5 +34,5 @@ public interface ICommandConverter<T> : ICommandConverter
3534
/// <param name="value">The <see cref="string"/> to convert. </param>
3635
/// <param name="propertyType">The property type that the converter will convert to.</param>
3736
/// <exception cref="NotSupportedException">The conversion cannot be performed.</exception>
38-
T ConvertFrom(CommandParser parser, CultureInfo culture, string value, Type propertyType);
37+
T? ConvertFrom(CommandParser parser, CultureInfo culture, string? value, Type propertyType);
3938
}

src/ImageSharp.Web/Commands/Converters/IntegralNumberConverter{T}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65

@@ -20,7 +19,7 @@ public sealed class IntegralNumberConverter<T> : ICommandConverter<T>
2019
public T ConvertFrom(
2120
CommandParser parser,
2221
CultureInfo culture,
23-
string value,
22+
string? value,
2423
Type propertyType)
2524
{
2625
if (string.IsNullOrWhiteSpace(value)

src/ImageSharp.Web/Commands/Converters/ListConverter{T}.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Runtime.CompilerServices;
@@ -21,7 +20,7 @@ public sealed class ListConverter<T> : ICommandConverter<List<T>>
2120
public List<T> ConvertFrom(
2221
CommandParser parser,
2322
CultureInfo culture,
24-
string value,
23+
string? value,
2524
Type propertyType)
2625
{
2726
var result = new List<T>();
@@ -32,7 +31,7 @@ public List<T> ConvertFrom(
3231

3332
foreach (string pill in GetStringArray(value, culture))
3433
{
35-
T item = parser.ParseValue<T>(pill, culture);
34+
T? item = parser.ParseValue<T>(pill, culture);
3635
if (item != null)
3736
{
3837
result.Add(item);

src/ImageSharp.Web/Commands/Converters/SimpleCommandConverter{T}.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Runtime.CompilerServices;
@@ -19,10 +18,10 @@ public sealed class SimpleCommandConverter<T> : ICommandConverter<T>
1918

2019
/// <inheritdoc/>
2120
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22-
public T ConvertFrom(
21+
public T? ConvertFrom(
2322
CommandParser parser,
2423
CultureInfo culture,
25-
string value,
24+
string? value,
2625
Type propertyType)
2726
{
2827
if (string.IsNullOrWhiteSpace(value))
@@ -31,7 +30,7 @@ public T ConvertFrom(
3130
}
3231

3332
Type t = typeof(T);
34-
Type u = Nullable.GetUnderlyingType(t);
33+
Type? u = Nullable.GetUnderlyingType(t);
3534

3635
if (u != null)
3736
{

0 commit comments

Comments
 (0)