BadScript 2
Loading...
Searching...
No Matches
TypeDescriptor.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4
5using CSharpx;
6
7namespace CommandLine.Core
8{
9 internal struct TypeDescriptor
10 {
11 private TypeDescriptor(TargetType targetType, Maybe<int> maxItems, Maybe<TypeDescriptor> nextValue = null)
12 {
13 TargetType = targetType;
14 MaxItems = maxItems;
15 NextValue = nextValue;
16 }
17
18 public TargetType TargetType { get; }
19
20 public Maybe<int> MaxItems { get; }
21
23
24 public static TypeDescriptor Create(TargetType tag, Maybe<int> maximumItems, TypeDescriptor next = default)
25 {
26 if (maximumItems == null)
27 {
28 throw new ArgumentNullException("maximumItems");
29 }
30
31 return new TypeDescriptor(tag, maximumItems, next.ToMaybe());
32 }
33 }
34
35 internal static class TypeDescriptorExtensions
36 {
37 public static TypeDescriptor WithNextValue(this TypeDescriptor descriptor, Maybe<TypeDescriptor> nextValue)
38 {
39 return TypeDescriptor.Create(descriptor.TargetType,
40 descriptor.MaxItems,
41 nextValue.GetValueOrDefault(default)
42 );
43 }
44 }
45}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
static TypeDescriptor WithNextValue(this TypeDescriptor descriptor, Maybe< TypeDescriptor > nextValue)
TypeDescriptor(TargetType targetType, Maybe< int > maxItems, Maybe< TypeDescriptor > nextValue=null)
static TypeDescriptor Create(TargetType tag, Maybe< int > maximumItems, TypeDescriptor next=default)
Maybe< TypeDescriptor > NextValue