2 using System
.Collections
.Generic
;
10 static class TypeHelper
{
12 public static AssemblyResolver Resolver
= new AssemblyResolver ();
14 internal static bool IsPublic (TypeReference typeref
)
17 throw new ArgumentNullException ("typeref");
19 TypeDefinition td
= typeref
.Resolve ();
23 internal static bool IsDelegate (TypeReference typeref
)
25 return IsDerivedFrom (typeref
, "System.MulticastDelegate");
28 internal static bool IsDerivedFrom (TypeReference type
, string derivedFrom
)
30 foreach (var def
in WalkHierarchy (type
))
31 if (def
.FullName
== derivedFrom
)
37 internal static IEnumerable
<TypeDefinition
> WalkHierarchy (TypeReference type
)
39 for (var def
= type
.Resolve (); def
!= null; def
= GetBaseType (def
))
43 internal static IEnumerable
<TypeReference
> GetInterfaces (TypeReference type
)
45 var ifaces
= new Dictionary
<string, TypeReference
> ();
47 foreach (var def
in WalkHierarchy (type
))
48 foreach (TypeReference iface
in def
.Interfaces
)
49 ifaces
[iface
.FullName
] = iface
;
54 internal static TypeDefinition
GetBaseType (TypeDefinition child
)
56 if (child
.BaseType
== null)
59 return child
.BaseType
.Resolve ();
62 internal static bool IsPublic (CustomAttribute att
)
64 return IsPublic (att
.Constructor
.DeclaringType
);
67 internal static string GetFullName (CustomAttribute att
)
69 return att
.Constructor
.DeclaringType
.FullName
;
72 internal static TypeDefinition
GetTypeDefinition (CustomAttribute att
)
74 return att
.Constructor
.DeclaringType
.Resolve ();