public static bool IsSimilarType(Type thisType, Mono.Cecil.TypeReference type) { Mono.Cecil.TypeDefinition td = type.Resolve(); // Ignore any 'ref' types if (thisType.IsByRef) { thisType = thisType.GetElementType(); } if (type.IsByReference) { type = type.GetElementType(); } // Handle array types if (thisType.IsArray && type.IsArray) { Mono.Cecil.ArrayType at = type as Mono.Cecil.ArrayType; // Dimensions must be the same. if (thisType.GetArrayRank() != at.Rank) { return(false); } // Base type of array must be the same. return(IsSimilarType(thisType.GetElementType(), type.GetElementType())); } if (thisType.IsArray && !type.IsArray) { return(false); } if (type.IsArray && !thisType.IsArray) { return(false); } // If the types are identical, or they're both generic parameters // or the special 'T' type, treat as a match // Match also if thisType is generic and type can be unified with thisType. if (thisType.Name == type.Name || // identical types. ((thisType.IsGenericParameter || thisType == typeof(T)) && (type.IsGenericParameter || type.Name.Equals("T"))) || // using "T" as matching generic type. IsUnifiableMono(thisType, type)) { return(true); } return(false); }
/// <summary> /// Converts a generic type description into a non-generic version /// </summary> /// <returns>The resolved type.</returns> /// <param name="ft">The type to resolve.</param> /// <param name="method">The method context, if any</param> public Mono.Cecil.TypeReference ResolveGenericType(Mono.Cecil.TypeReference ft, MethodState method = null) { if (ft != null) { if (ft.IsArray) { var elt = ft.GetElementType(); if (elt.IsGenericParameter) { return(Mono.Cecil.Rocks.TypeReferenceRocks.MakeArrayType(this.GenericTypes[elt.Name])); } } else if (ft.IsGenericParameter) { return(this.GenericTypes[ft.Name]); } } return(ft); }