forked from dnSpy/ILSpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CecilType.cs
86 lines (70 loc) · 1.74 KB
/
CecilType.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Linq;
using ICSharpCode.ILSpy;
using Mono.Cecil;
using Ricciolo.StylesExplorer.MarkupReflection;
namespace ILSpy.BamlDecompiler
{
public class CecilType : IType
{
internal readonly TypeDefinition type;
public CecilType(TypeDefinition type)
{
if (type == null)
throw new ArgumentNullException("type");
this.type = type;
}
public string AssemblyQualifiedName {
get {
return type.FullName +
", " + type.Module.Assembly.FullName;
}
}
public bool IsSubclassOf(IType type)
{
if (type == null)
throw new ArgumentNullException("type");
if (!(type is CecilType))
return false;
CecilType ct = (CecilType)type;
var t = this.type;
if (t == ct.type)
return false;
while (t != null) {
if (t == ct.type)
return true;
foreach (var @interface in t.Interfaces) {
var resolved = @interface.Resolve();
if (resolved == ct.type)
return true;
}
if (t.BaseType == null)
break;
t = t.BaseType.Resolve();
}
return false;
}
public bool Equals(IType type)
{
if (type == null)
throw new ArgumentNullException("type");
if (!(type is CecilType))
return false;
return this.type == ((CecilType)type).type;
}
public override string ToString()
{
return string.Format("[CecilType Type={0}]", type);
}
public IType BaseType {
get {
TypeDefinition td = type.BaseType.Resolve();
if (td == null)
throw new Exception("could not resolve '" + type.BaseType.FullName + "'!");
return new CecilType(td);
}
}
}
}