UBT: Fix parsing of nullable arguments passed via command line arguments.

#rb none
[fyi] pj.kack
#rnx

(ushell-p4-cherrypick of 8382982 by Ben.Marsh)

[CL 8395389 by PJ Kack in Dev-Core branch]
This commit is contained in:
PJ Kack
2019-09-02 02:31:02 -04:00
parent feb8dcf960
commit f074937e40
@@ -593,11 +593,18 @@ namespace Tools.DotNETCommon
IEnumerable<CommandLineAttribute> Attributes = FieldInfo.GetCustomAttributes<CommandLineAttribute>();
foreach(CommandLineAttribute Attribute in Attributes)
{
// Get the inner field type, unwrapping nullable types
Type ValueType = FieldInfo.FieldType;
if(ValueType.IsGenericType && ValueType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
ValueType = ValueType.GetGenericArguments()[0];
}
// Get the appropriate prefix for this attribute
string Prefix = Attribute.Prefix;
if(Prefix == null)
{
if(FieldInfo.FieldType == typeof(bool))
if(ValueType == typeof(bool))
{
Prefix = String.Format("-{0}", FieldInfo.Name);
}
@@ -608,7 +615,7 @@ namespace Tools.DotNETCommon
}
else
{
if(FieldInfo.FieldType != typeof(bool) && Attribute.Value == null && !Prefix.EndsWith("=") && !Prefix.EndsWith(":"))
if(ValueType != typeof(bool) && Attribute.Value == null && !Prefix.EndsWith("=") && !Prefix.EndsWith(":"))
{
Prefix = Prefix + "=";
}