Skip to content

Commit 9c0bcde

Browse files
Fix not supported exceptions
1 parent 4c7c2a8 commit 9c0bcde

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -15,10 +15,9 @@ internal sealed class EnumConverter : CommandConverter
1515
/// <inheritdoc/>
1616
public override object ConvertFrom(CultureInfo culture, string value, Type propertyType)
1717
{
18-
if (value == null)
18+
if (string.IsNullOrWhiteSpace(value))
1919
{
20-
// TODO: How can we get the default enum, or should we return null?
21-
return base.ConvertFrom(culture, null, propertyType);
20+
return Activator.CreateInstance(propertyType);
2221
}
2322

2423
try
@@ -51,4 +50,4 @@ public override object ConvertFrom(CultureInfo culture, string value, Type prope
5150
/// <returns>The <see cref="T:String[]"/>.</returns>
5251
private static string[] GetStringArray(string input, char separator) => input.Split(separator).Select(s => s.Trim()).ToArray();
5352
}
54-
}
53+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ internal sealed class IntegralNumberConverter<T> : CommandConverter
1616
/// <inheritdoc/>
1717
public override object ConvertFrom(CultureInfo culture, string value, Type propertyType)
1818
{
19-
if (value == null || Array.IndexOf(TypeConstants.IntegralTypes, propertyType) < 0)
19+
if (string.IsNullOrWhiteSpace(value)
20+
|| Array.IndexOf(TypeConstants.IntegralTypes, propertyType) < 0)
2021
{
21-
return base.ConvertFrom(culture, null, propertyType);
22+
return default(T);
2223
}
2324

2425
// Round the value to the nearest decimal value

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

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

44
using System;
@@ -17,6 +17,12 @@ internal class ListConverter<T> : CommandConverter
1717
/// <inheritdoc/>
1818
public override object ConvertFrom(CultureInfo culture, string value, Type propertyType)
1919
{
20+
var result = new List<T>();
21+
if (string.IsNullOrWhiteSpace(value))
22+
{
23+
return result;
24+
}
25+
2026
Type type = typeof(T);
2127
ICommandConverter paramConverter = CommandDescriptor.GetConverter(type);
2228

@@ -25,17 +31,12 @@ public override object ConvertFrom(CultureInfo culture, string value, Type prope
2531
throw new InvalidOperationException("No type converter exists for type " + type.FullName);
2632
}
2733

28-
var result = new List<T>();
29-
30-
if (value != null)
34+
foreach (string pill in this.GetStringArray(value, culture))
3135
{
32-
foreach (string pill in this.GetStringArray(value, culture))
36+
object item = paramConverter.ConvertFromInvariantString(pill, type);
37+
if (item != null)
3338
{
34-
object item = paramConverter.ConvertFromInvariantString(pill, type);
35-
if (item != null)
36-
{
37-
result.Add((T)item);
38-
}
39+
result.Add((T)item);
3940
}
4041
}
4142

@@ -54,4 +55,4 @@ protected string[] GetStringArray(string input, CultureInfo culture)
5455
return input.Split(separator).Select(s => s.Trim()).ToArray();
5556
}
5657
}
57-
}
58+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -16,7 +16,7 @@ internal sealed class SimpleCommandConverter<T> : CommandConverter
1616
/// <inheritdoc/>
1717
public override object ConvertFrom(CultureInfo culture, string value, Type propertyType)
1818
{
19-
if (value == null)
19+
if (string.IsNullOrWhiteSpace(value))
2020
{
2121
return default(T);
2222
}
@@ -32,4 +32,4 @@ public override object ConvertFrom(CultureInfo culture, string value, Type prope
3232
return (T)Convert.ChangeType(value, t, culture);
3333
}
3434
}
35-
}
35+
}

0 commit comments

Comments
 (0)