-
Notifications
You must be signed in to change notification settings - Fork 2
/
TypeReference.cs
44 lines (36 loc) · 970 Bytes
/
TypeReference.cs
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
using System;
namespace TypeInspector
{
/// <summary>
/// Make reference for type and create editor interface
/// </summary>
[Serializable]
public class TypeReference
{
public string FullName;
private Type _typeCache;
/// <summary>
/// Get selected type
/// </summary>
/// <returns> if all is ok, returns Type object, or return null </returns>
public Type Get()
{
if (_typeCache == null && !IsValid())
{
return null;
}
if(_typeCache != null)
{
return _typeCache;
}
_typeCache = Type.GetType(FullName);
return _typeCache;
}
public bool IsValid() => !string.IsNullOrEmpty(FullName) && Type.GetType(FullName) != null;
public void ClearCache()
{
_typeCache = null;
}
}
}