-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Class_ClrTypeUtil.xpp
55 lines (44 loc) · 1.46 KB
/
Class_ClrTypeUtil.xpp
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
53
54
55
//
// https://github.com/mazzy-ax/SysUtil
//
// Util-класс реализует только статические методы.
// не содержит внутри никаких значений.
// не имеет смысла создавать экземпляр этого класса.
//
abstract class ClrTypeUtil
{
// mazzy, 06.10.2020
public static System.Object asInstance(System.Object obj, System.Object baseObj)
{
if( ClrTypeUtil::isInstance(obj, baseObj) )
{
return obj;
}
return null;
}
// mazzy, 06.10.2020
public static System.Object asInstanceOrBase(System.Object obj, System.Object baseObj)
{
if( ClrTypeUtil::isInstance(obj, baseObj) )
{
return obj;
}
return baseObj;
}
// mazzy, 06.10.2020
public static boolean isInstance(System.Object obj, System.Object baseObj)
{
anytype perm = new InteropPermission(Interopkind::ClrInterop).assert();
System.Type baseType = baseObj ? baseObj.GetType() : null;
boolean ret = baseType && obj ? baseType.IsInstanceOfType(obj) : false;
return ret;
}
// mazzy, 06.10.2020
public static str name(System.Object obj)
{
anytype perm = new InteropPermission(InteropKind::ClrInterop).assert();
System.Type type = obj ? obj.GetType() : null;
str typeName = type ? type.get_Name() : '';
return typeName;
}
}