From 55bf655ba1415043ee2108402f021a79f3ec87ff Mon Sep 17 00:00:00 2001 From: pic-Nick Date: Wed, 28 Nov 2018 17:57:55 +0300 Subject: [PATCH] Fixed #115: Missing required values on immutable targets causes exception --- src/CommandLine/Core/InstanceBuilder.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CommandLine/Core/InstanceBuilder.cs b/src/CommandLine/Core/InstanceBuilder.cs index 01597ac4..ad6b5d52 100644 --- a/src/CommandLine/Core/InstanceBuilder.cs +++ b/src/CommandLine/Core/InstanceBuilder.cs @@ -106,9 +106,13 @@ public static ParserResult Build( { var ctor = typeInfo.GetTypeInfo().GetConstructor((from sp in specProps select sp.Property.PropertyType).ToArray()); var values = (from prms in ctor.GetParameters() - join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToLower() + join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToLower() into spv + from sp in spv.DefaultIfEmpty() select - sp.Value.GetValueOrDefault( + sp == null + ? specProps.First(s => String.Equals(s.Property.Name, prms.Name, StringComparison.CurrentCultureIgnoreCase)) + .Property.PropertyType.GetDefaultValue() + : sp.Value.GetValueOrDefault( sp.Specification.DefaultValue.GetValueOrDefault( sp.Specification.ConversionType.CreateDefaultForImmutable()))).ToArray(); var immutable = (T)ctor.Invoke(values);