forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeDescriptor.cs
More file actions
51 lines (42 loc) · 1.61 KB
/
TypeDescriptor.cs
File metadata and controls
51 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using CSharpx;
namespace CommandLine.Core
{
struct TypeDescriptor
{
private readonly TargetType targetType;
private readonly Maybe<int> maxItems;
private readonly Maybe<TypeDescriptor> nextValue;
private TypeDescriptor(TargetType targetType, Maybe<int> maxItems, Maybe<TypeDescriptor> nextValue = null)
{
this.targetType = targetType;
this.maxItems = maxItems;
this.nextValue = nextValue;
}
public TargetType TargetType
{
get { return targetType; }
}
public Maybe<int> MaxItems
{
get { return maxItems; }
}
public Maybe<TypeDescriptor> NextValue
{
get { return this.nextValue; }
}
public static TypeDescriptor Create(TargetType tag, Maybe<int> maximumItems, TypeDescriptor next = default(TypeDescriptor))
{
if (maximumItems == null) throw new ArgumentNullException("maximumItems");
return new TypeDescriptor(tag, maximumItems, next.ToMaybe());
}
}
static class TypeDescriptorExtensions
{
public static TypeDescriptor WithNextValue(this TypeDescriptor descriptor, Maybe<TypeDescriptor> nextValue)
{
return TypeDescriptor.Create(descriptor.TargetType, descriptor.MaxItems, nextValue.GetValueOrDefault(default(TypeDescriptor)));
}
}
}