Skip to content

Commit 3c8dc8f

Browse files
committed
Feedback
1 parent 672b04b commit 3c8dc8f

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,14 +2001,7 @@ private static Expression CreateDefaultValueExpression(object? defaultValue, Typ
20012001
}
20022002
else if (!targetType.IsAssignableFrom(defaultValue.GetType()))
20032003
{
2004-
try
2005-
{
2006-
converted = Convert.ChangeType(defaultValue, targetType, CultureInfo.InvariantCulture);
2007-
}
2008-
catch
2009-
{
2010-
converted = targetType.IsValueType ? Activator.CreateInstance(targetType) : null;
2011-
}
2004+
converted = Convert.ChangeType(defaultValue, targetType, CultureInfo.InvariantCulture);
20122005
}
20132006

20142007
var constant = Expression.Constant(converted, targetType);

src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.SpecialTypes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public static object[][] DefaultValues
197197
["decimal", "decimal.Zero", decimal.Zero, true],
198198
["long", "long.MaxValue", long.MaxValue, true],
199199
["long", "long.MinValue", long.MinValue, true],
200+
["long", "(long)3.14", (long)3, true],
200201
["short", "short.MaxValue", short.MaxValue, true],
201202
["short", "short.MinValue", short.MinValue, true],
202203
["ulong", "ulong.MaxValue", ulong.MaxValue, true],
@@ -206,6 +207,7 @@ public static object[][] DefaultValues
206207
["TodoStatus", "TodoStatus.Done", TodoStatus.Done, true],
207208
["TodoStatus", "TodoStatus.InProgress", TodoStatus.InProgress, true],
208209
["TodoStatus", "TodoStatus.NotDone", TodoStatus.NotDone, true],
210+
["TodoStatus", "(TodoStatus)1", TodoStatus.Done, true],
209211
["MyEnum", "MyEnum.ValueA", MyEnum.ValueA, true],
210212
["MyEnum", "MyEnum.ValueB", MyEnum.ValueB, true],
211213
// Test nullable enum values

src/Shared/RoslynUtils/SymbolExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ private static bool IsEnumType(ITypeSymbol typeSymbol, out ITypeSymbol enumType)
250250
return typeSymbol.TypeKind == TypeKind.Enum;
251251
}
252252

253-
private static bool IsNullableEnumType(ITypeSymbol typeSymbol, out ITypeSymbol underlyingEnumType)
253+
private static bool IsNullableEnumType(ITypeSymbol typeSymbol, [NotNullWhen(true)] out ITypeSymbol? underlyingEnumType)
254254
{
255-
underlyingEnumType = null!;
255+
underlyingEnumType = null;
256256
if (typeSymbol.OriginalDefinition?.SpecialType == SpecialType.System_Nullable_T &&
257257
typeSymbol is INamedTypeSymbol namedType)
258258
{

0 commit comments

Comments
 (0)