diff --git a/src/CommandLine/Core/InstanceBuilder.cs b/src/CommandLine/Core/InstanceBuilder.cs index 608104b6..0c24fddd 100644 --- a/src/CommandLine/Core/InstanceBuilder.cs +++ b/src/CommandLine/Core/InstanceBuilder.cs @@ -67,7 +67,7 @@ public static ParserResult Build( var valueSpecPropsResult = ValueMapper.MapValues( - (from pt in specProps where pt.Specification.IsValue() select pt), + (from pt in specProps where pt.Specification.IsValue() orderby ((ValueSpecification)pt.Specification).Index select pt), valuesPartition, (vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, parsingCulture, ignoreValueCase)); diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 42258a25..0d6213ed 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -61,6 +61,7 @@ + diff --git a/tests/CommandLine.Tests/Fakes/Options_With_Shuffled_Index_Values.cs b/tests/CommandLine.Tests/Fakes/Options_With_Shuffled_Index_Values.cs new file mode 100644 index 00000000..63a9a197 --- /dev/null +++ b/tests/CommandLine.Tests/Fakes/Options_With_Shuffled_Index_Values.cs @@ -0,0 +1,19 @@ +// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information. + +using System; +using System.Linq; + +namespace CommandLine.Tests.Fakes +{ + class Options_With_Shuffled_Index_Values + { + [Value(1)] + public string Arg1 { get; set; } + + [Value(2)] + public string Arg2 { get; set; } + + [Value(0)] + public string Arg0 { get; set; } + } +} diff --git a/tests/CommandLine.Tests/Unit/ParserTests.cs b/tests/CommandLine.Tests/Unit/ParserTests.cs index a0cc1923..76426887 100644 --- a/tests/CommandLine.Tests/Unit/ParserTests.cs +++ b/tests/CommandLine.Tests/Unit/ParserTests.cs @@ -803,5 +803,20 @@ public class NullDefaultCommandLineArguments [Option('u', "user", Default = null)] public string User { get; set; } } + + [Fact] + public void Parse_options_with_shuffled_index_values() + { + var parser = Parser.Default; + parser.ParseArguments( + new[] { "zero", "one", "two" }) + .WithNotParsed(errors => { throw new InvalidOperationException("Must be parsed."); }) + .WithParsed(args => + { + Assert.Equal("zero", args.Arg0); + Assert.Equal("one", args.Arg1); + Assert.Equal("two", args.Arg2); + }); + } } }