This repository was archived by the owner on Jul 11, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +37
-15
lines changed Expand file tree Collapse file tree 5 files changed +37
-15
lines changed Original file line number Diff line number Diff line change 5959 <Link >Properties\SharedAssemblyInfo.cs</Link >
6060 </Compile >
6161 <Compile Include =" Fakes\FakeOptionsWithNullable.cs" />
62+ <Compile Include =" Fakes\FakeOptionsWithNullDefault.cs" />
6263 <Compile Include =" Fakes\FakeOptionsWithTwoIntegers.cs" />
6364 <Compile Include =" Fakes\FakeInterfaceOptions.cs" />
6465 <Compile Include =" Fakes\FakeOptionsWithHelpTextEnum.cs" />
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+
3+ namespace CommandLine . Tests . Fakes
4+ {
5+ class FakeOptionsWithNullDefault
6+ {
7+ [ Option ( 'i' , DefaultValue = null ) ]
8+ public IEnumerable < int > IntSequence
9+ {
10+ get { return intSequence ; }
11+ set { intSequence = value ; }
12+ }
13+ private IEnumerable < int > intSequence ;
14+ }
15+ }
Original file line number Diff line number Diff line change @@ -247,5 +247,19 @@ public void Parse_nullable_options()
247247 Assert . False ( result . Errors . Any ( ) ) ;
248248 // Teardown
249249 }
250+
251+ [ Fact ]
252+ public void Parse_allow_null_default_value ( )
253+ {
254+ // Fixture setup
255+ var sut = new Parser ( ) ;
256+
257+ // Exercize system
258+ var result = sut . ParseArguments < FakeOptionsWithNullDefault > ( new string [ 0 ] ) ;
259+
260+ // Verify outcome
261+ Assert . Null ( result . Value . IntSequence ) ;
262+ // Teardown
263+ }
250264 }
251265}
Original file line number Diff line number Diff line change @@ -80,12 +80,12 @@ public static ParserResult<T> Build<T>(
8080 sp => sp . Value . FromJust ( ) )
8181 . SetProperties ( specPropsWithValue ,
8282 sp => sp . Value . IsNothing ( ) && sp . Specification . DefaultValue . IsJust ( ) ,
83- sp => sp . Specification . DefaultValue . FromJust ( ) )
84- . SetProperties ( specPropsWithValue ,
85- sp => sp . Value . IsNothing ( )
86- && sp . Specification . ConversionType . ToDescriptor ( ) == DescriptorType . Sequence
87- && sp . Specification . DefaultValue . MatchNothing ( ) ,
88- sp => sp . Property . PropertyType . GetGenericArguments ( ) . Single ( ) . CreateEmptyArray ( ) ) ;
83+ sp => sp . Specification . DefaultValue . FromJust ( ) ) ;
84+ // .SetProperties(specPropsWithValue,
85+ // sp => sp.Value.IsNothing()
86+ // && sp.Specification.ConversionType.ToDescriptor() == DescriptorType.Sequence
87+ // && sp.Specification.DefaultValue.MatchNothing(),
88+ // sp => sp.Property.PropertyType.GetGenericArguments().Single().CreateEmptyArray());
8989
9090 var validationErrors = specPropsWithValue . Validate ( SpecificationPropertyRules . Lookup )
9191 . OfType < Just < Error > > ( ) . Select ( e => e . Value ) ;
Original file line number Diff line number Diff line change @@ -153,15 +153,7 @@ public int Max
153153 public object DefaultValue
154154 {
155155 get { return this . defaultValue ; }
156- set
157- {
158- if ( value == null )
159- {
160- throw new ArgumentNullException ( "value" ) ;
161- }
162-
163- this . defaultValue = value ;
164- }
156+ set { this . defaultValue = value ; }
165157 }
166158
167159 /// <summary>
You can’t perform that action at this time.
0 commit comments