From a390ddb1d2891167c3a4d4d405207409834b5b42 Mon Sep 17 00:00:00 2001 From: ohadschn Date: Fri, 1 Dec 2017 00:36:40 +0200 Subject: [PATCH] Change string argument default to null Instead of String.Empty ("") Closes https://github.com/commandlineparser/commandline/issues/187 --- src/CommandLine/Core/ReflectionExtensions.cs | 4 ---- tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/CommandLine/Core/ReflectionExtensions.cs b/src/CommandLine/Core/ReflectionExtensions.cs index 3b011316..068b3034 100644 --- a/src/CommandLine/Core/ReflectionExtensions.cs +++ b/src/CommandLine/Core/ReflectionExtensions.cs @@ -153,10 +153,6 @@ public static bool IsMutable(this Type type) public static object CreateDefaultForImmutable(this Type type) { - if (type == typeof(string)) - { - return string.Empty; - } if (type.GetTypeInfo().IsGenericType && type.GetTypeInfo().GetGenericTypeDefinition() == typeof(IEnumerable<>)) { return type.GetTypeInfo().GetGenericArguments()[0].CreateEmptyArray(); diff --git a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs index da6d6c5b..7d7544e6 100644 --- a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs +++ b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs @@ -1052,11 +1052,11 @@ public static IEnumerable ImmutableInstanceData { get { - yield return new object[] { new string[] { }, new Immutable_Simple_Options("", new int[] { }, default(bool), default(long)) }; + yield return new object[] { new string[] { }, new Immutable_Simple_Options(null, new int[] { }, default(bool), default(long)) }; yield return new object[] { new[] { "--stringvalue=strval0" }, new Immutable_Simple_Options("strval0", new int[] { }, default(bool), default(long)) }; - yield return new object[] { new[] { "-i", "9", "7", "8" }, new Immutable_Simple_Options("", new[] { 9, 7, 8 }, default(bool), default(long)) }; - yield return new object[] { new[] { "-x" }, new Immutable_Simple_Options("", new int[] { }, true, default(long)) }; - yield return new object[] { new[] { "9876543210" }, new Immutable_Simple_Options("", new int[] { }, default(bool), 9876543210L) }; + yield return new object[] { new[] { "-i", "9", "7", "8" }, new Immutable_Simple_Options(null, new[] { 9, 7, 8 }, default(bool), default(long)) }; + yield return new object[] { new[] { "-x" }, new Immutable_Simple_Options(null, new int[] { }, true, default(long)) }; + yield return new object[] { new[] { "9876543210" }, new Immutable_Simple_Options(null, new int[] { }, default(bool), 9876543210L) }; yield return new object[] { new[] { "--stringvalue=strval0", "-i", "9", "7", "8", "-x", "9876543210" }, new Immutable_Simple_Options("strval0", new[] { 9, 7, 8 }, true, 9876543210L) }; } }