public TypeDefinition GetTypeDefinition (TypeReference type) { if (type == null) return null; TypeDefinition typeDef = type as TypeDefinition; if (typeDef != null) return typeDef; AssemblyNameReference name = type.Scope as AssemblyNameReference; if (name == null) { GenericInstanceType gi = type as GenericInstanceType; return gi == null ? null : GetTypeDefinition (gi.ElementType); } AssemblyDefinition assmDef; try { assmDef = Resolve (name); } catch (FileNotFoundException) { throw new ObfuscarException ("Unable to resolve dependency: " + name.Name); } string fullName = type.GetFullName (); typeDef = assmDef.MainModule.GetType (fullName); return typeDef; }
public TypeDefinition GetTypeDefinition (TypeReference type) { if (type == null) return null; TypeDefinition typeDef = type as TypeDefinition; if (typeDef != null) return typeDef; AssemblyNameReference name = type.Scope as AssemblyNameReference; if (name == null) { GenericInstanceType gi = type as GenericInstanceType; return gi == null ? null : GetTypeDefinition (gi.ElementType); } AssemblyDefinition assmDef; try { assmDef = Resolve (name); } catch (FileNotFoundException) { throw new ObfuscarException ("Unable to resolve dependency: " + name.Name); } string fullName = type.GetFullName (); typeDef = assmDef.MainModule.GetType (fullName); if (typeDef != null) return typeDef; // IMPORTANT: handle type forwarding if (!assmDef.MainModule.HasExportedTypes) return null; foreach (var exported in assmDef.MainModule.ExportedTypes) { if (exported.FullName == fullName) return exported.Resolve (); } return null; }
private void GetMethods (TypeReference type) { string full_name = type.GetFullName (); args1 [0] = full_name; AddMethod (type.GetMethod (MethodSignatures.Equals)); AddMethod (type.GetMethod ("Equals", "System.Boolean", args1)); AddMethod (type.GetMethod ("CompareTo", "System.Int32", args1)); // generic version AddMethod (type.GetMethod (CompareTo)); // non-generic version // Note that we don't want to use MethodSignatures for these // because we don't want any weird overloads. args2 [0] = full_name; args2 [1] = full_name; AddMethod (type.GetMethod ("op_Equality", "System.Boolean", args2)); AddMethod (type.GetMethod ("op_Inequality", "System.Boolean", args2)); AddMethod (type.GetMethod ("op_LessThan", "System.Boolean", args2)); AddMethod (type.GetMethod ("op_LessThanOrEqual", "System.Boolean", args2)); AddMethod (type.GetMethod ("op_GreaterThan", "System.Boolean", args2)); AddMethod (type.GetMethod ("op_GreaterThanOrEqual", "System.Boolean", args2)); clone.Method = type.GetMethod (MethodSignatures.Clone); hash.Method = type.GetMethod (MethodSignatures.GetHashCode); }
private bool IsRule (TypeReference type) { var typeName = type.GetFullName (); bool result; if (!typeIsRule.TryGetValue (typeName, out result)) { result = type.Implements ("Gendarme.Framework", "IRule"); typeIsRule [typeName] = result; } return result; }
private static void AppendPrettyTypeName(StringBuilder sb, TypeReference type) { int nRemoveTrail; IList<GenericParameter> gpc = type.GenericParameters; int count = gpc.Count; if (count == 0) nRemoveTrail = 0; else if (count < 10) nRemoveTrail = 2; else nRemoveTrail = 3; string fullname = type.GetFullName (); sb.Append (fullname.Substring (0, fullname.Length - nRemoveTrail)); if (count > 0) { int n = 0; sb.Append ("<"); foreach (GenericParameter gp in gpc) { if (n > 0) sb.Append (","); AppendPrettyTypeName (sb, gp); n++; } sb.Append (">"); } }
static string InheritFromWeakType (TypeReference type, string nameSpace, string name) { if (!type.Inherits (nameSpace, name)) return String.Empty; return String.Format (CultureInfo.InvariantCulture, "'{0}' inherits from '{1}.{2}'.", type.GetFullName (), nameSpace, name); }