forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSharpOptionHelper.cs
More file actions
49 lines (43 loc) · 1.43 KB
/
Copy pathFSharpOptionHelper.cs
File metadata and controls
49 lines (43 loc) · 1.43 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
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using CommandLine.Core;
using Microsoft.FSharp.Core;
namespace CommandLine.Infrastructure
{
static class FSharpOptionHelper
{
public static Type GetUnderlyingType(Type type)
{
return type
.GetGenericArguments()[0];
}
public static object Some(Type type, object value)
{
return typeof(FSharpOption<>)
.MakeGenericType(type)
.StaticMethod(
"Some", value);
}
public static object None(Type type)
{
return typeof(FSharpOption<>)
.MakeGenericType(type)
.StaticProperty(
"None");
}
public static object ValueOf(object value)
{
return typeof(FSharpOption<>)
.MakeGenericType(GetUnderlyingType(value.GetType()))
.InstanceProperty(
"Value", value);
}
public static bool IsSome(object value)
{
return (bool)typeof(FSharpOption<>)
.MakeGenericType(GetUnderlyingType(value.GetType()))
.StaticMethod(
"get_IsSome", value);
}
}
}