Skip to content

Commit 3264927

Browse files
committed
fix #1137
1 parent 56139ef commit 3264927

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/System.CommandLine.Tests/Binding/ModelBinderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Binding;
66
using System.CommandLine.Builder;
77
using System.CommandLine.Invocation;
8+
using System.CommandLine.IO;
89
using System.CommandLine.Parsing;
910
using System.IO;
1011
using FluentAssertions;
@@ -769,5 +770,29 @@ public async Task Empty_input_is_bound_correctly_to_list_type_properties()
769770

770771
boundInstance.Should().NotBeNull();
771772
}
773+
774+
[Fact]
775+
public async Task Decimals_are_bound_correctly_when_no_token_is_matched()
776+
{
777+
decimal? receivedValue = null;
778+
779+
var rootCommand = new RootCommand
780+
{
781+
new Option<decimal>("--opt-decimal")
782+
};
783+
rootCommand.Handler = CommandHandler.Create((ComplexType options) =>
784+
{
785+
receivedValue = options.OptDecimal;
786+
});
787+
788+
await rootCommand.InvokeAsync("");
789+
790+
receivedValue.Should().Be(0);
791+
}
792+
793+
public class ComplexType
794+
{
795+
public decimal OptDecimal { get; set; }
796+
}
772797
}
773798
}

src/System.CommandLine/Binding/ModelBinder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private bool ShortCutTheBinding()
105105
var modelType = ModelDescriptor.ModelType;
106106
return modelType.IsPrimitive ||
107107
modelType.IsNullableValueType() ||
108-
modelType == typeof(string);
108+
modelType == typeof(string) ||
109+
modelType == typeof(decimal) ;
109110
}
110111

111112
private (bool success, object? newInstance, bool anyNonDefaults) GetSimpleModelValue(

0 commit comments

Comments
 (0)