Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed May 25, 2021
1 parent 56139ef commit 3264927
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/System.CommandLine.Tests/Binding/ModelBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.CommandLine.Binding;
using System.CommandLine.Builder;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.Parsing;
using System.IO;
using FluentAssertions;
Expand Down Expand Up @@ -769,5 +770,29 @@ public async Task Empty_input_is_bound_correctly_to_list_type_properties()

boundInstance.Should().NotBeNull();
}

[Fact]
public async Task Decimals_are_bound_correctly_when_no_token_is_matched()
{
decimal? receivedValue = null;

var rootCommand = new RootCommand
{
new Option<decimal>("--opt-decimal")
};
rootCommand.Handler = CommandHandler.Create((ComplexType options) =>
{
receivedValue = options.OptDecimal;
});

await rootCommand.InvokeAsync("");

receivedValue.Should().Be(0);
}

public class ComplexType
{
public decimal OptDecimal { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion src/System.CommandLine/Binding/ModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private bool ShortCutTheBinding()
var modelType = ModelDescriptor.ModelType;
return modelType.IsPrimitive ||
modelType.IsNullableValueType() ||
modelType == typeof(string);
modelType == typeof(string) ||
modelType == typeof(decimal) ;
}

private (bool success, object? newInstance, bool anyNonDefaults) GetSimpleModelValue(
Expand Down

0 comments on commit 3264927

Please sign in to comment.