BadScript 2
Loading...
Searching...
No Matches
FSharpOptionHelper.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;
5using Microsoft.FSharp.Core;
6
8{
9 static class FSharpOptionHelper
10 {
11 public static Type GetUnderlyingType(Type type)
12 {
13 return type
14 .GetGenericArguments()[0];
15 }
16
17 public static object Some(Type type, object value)
18 {
19 return typeof(FSharpOption<>)
20 .MakeGenericType(type)
21 .StaticMethod(
22 "Some", value);
23 }
24
25 public static object None(Type type)
26 {
27 return typeof(FSharpOption<>)
28 .MakeGenericType(type)
29 .StaticProperty(
30 "None");
31 }
32
33 public static object ValueOf(object value)
34 {
35 return typeof(FSharpOption<>)
36 .MakeGenericType(GetUnderlyingType(value.GetType()))
37 .InstanceProperty(
38 "Value", value);
39 }
40
41 public static bool IsSome(object value)
42 {
43 return (bool)typeof(FSharpOption<>)
44 .MakeGenericType(GetUnderlyingType(value.GetType()))
45 .StaticMethod(
46 "get_IsSome", value);
47 }
48 }
49}
static object Some(Type type, object value)