2 using System.Collections.Generic;
6 namespace Mono.Util.CorCompare.Cecil {
8 static class TypeHelper {
10 public static AssemblyResolver Resolver = new AssemblyResolver ();
12 internal static bool IsPublic (TypeReference typeref)
15 throw new ArgumentException ("typeref must not be null");
17 TypeDefinition td = Resolve (typeref);
21 internal static bool IsDelegate (TypeReference typeref)
23 return IsDerivedFrom (typeref, "System.MulticastDelegate");
26 static TypeDefinition Resolve (TypeReference reference)
28 return Resolver.Resolve (reference);
31 internal static bool IsDerivedFrom (TypeReference type, string derivedFrom)
33 foreach (var def in WalkHierarchy (type))
34 if (def.FullName == derivedFrom)
40 internal static IEnumerable<TypeDefinition> WalkHierarchy (TypeReference type)
42 for (var def = Resolve (type); def != null; def = GetBaseType (def))
46 internal static IEnumerable<TypeReference> GetInterfaces (TypeReference type)
48 var ifaces = new Dictionary<string, TypeReference> ();
50 foreach (var def in WalkHierarchy (type))
51 foreach (TypeReference iface in def.Interfaces)
52 ifaces [iface.FullName] = iface;
57 internal static TypeDefinition GetBaseType (TypeDefinition child)
59 if (child.BaseType == null)
62 return Resolve (child.BaseType);
65 internal static bool IsPublic (CustomAttribute att)
67 return IsPublic (att.Constructor.DeclaringType);
70 internal static string GetFullName (CustomAttribute att)
72 return att.Constructor.DeclaringType.FullName;
75 internal static TypeDefinition GetTypeDefinition (CustomAttribute att)
77 return Resolve (att.Constructor.DeclaringType);