-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathScriptManager.cs
60 lines (51 loc) · 1.6 KB
/
ScriptManager.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DigitalPlatform.Interfaces
{
public class ScriptManager
{
// 获得从指定类或者接口派生的类
public static Type GetDerivedClassType(Assembly assembly,
string strBaseTypeFullName)
{
if (assembly == null)
return null;
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsClass == false)
continue;
// 2015/5/28
Type[] interfaces = type.GetInterfaces();
foreach (Type inter in interfaces)
{
if (inter.FullName == strBaseTypeFullName)
return type;
}
if (IsDerivedFrom(type,
strBaseTypeFullName) == true)
return type;
}
return null;
}
// 观察type的基类中是否有类名为strBaseTypeFullName的类。
public static bool IsDerivedFrom(Type type,
string strBaseTypeFullName)
{
Type curType = type;
for (; ; )
{
if (curType == null
|| curType.FullName == "System.Object")
return false;
if (curType.FullName == strBaseTypeFullName)
return true;
curType = curType.BaseType;
}
}
}
}