-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflect.cs
More file actions
52 lines (48 loc) · 1.66 KB
/
Reflect.cs
File metadata and controls
52 lines (48 loc) · 1.66 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
52
using System;
using LangExt;
namespace ReflectionExt
{
/// <summary>
/// ReflectionExtのエントリポイントとなる、TypeSketchオブジェクトを取得するためのクラスです。
/// </summary>
public static class Reflect
{
/// <summary>
/// System.TypeオブジェクトからTypeSketchオブジェクトを構築します。
/// </summary>
public static TypeSketch Type(Type type)
{
return new TypeSketch(type);
}
/// <summary>
/// 型パラメータで指定した型からTypeSketchオブジェクトを構築します。
/// </summary>
public static TypeSketch Type<T>()
{
return new TypeSketch(typeof(T));
}
/// <summary>
/// 型名からTypeSketchオブジェクトの構築を試みます。
/// 型の構築に失敗した場合、Option.Noneが返されます。
/// </summary>
public static Option<TypeSketch> Type(string typeName)
{
try
{
return Option.Some(new TypeSketch(System.Type.GetType(typeName, true)));
}
catch
{
return Option.None;
}
}
/// <summary>
/// 型名からTypeSketchオブジェクトの構築を試みます。
/// 型の構築に失敗した場合、例外が投げられます。
/// </summary>
public static TypeSketch TypeUnsafe(string typeName)
{
return new TypeSketch(System.Type.GetType(typeName, true));
}
}
}