public static RewritedCacheRecord <TypeReference> Normalized(TypeReference declaringType) { var targetMappings = new Dictionary <GenericParameter, int>(new GenericParameterComparer()); var resolvedType = GenericTypesRewriter.ResolveTypeReference( declaringType, (tr, resolutionStack) => { if (tr is GenericParameter) { var gp = (GenericParameter)tr; return(GenericTypesRewriter.ReplaceWithGenericArgument(gp, targetMappings)); } return(tr); }, null); var mappings = targetMappings.OrderBy(item => item.Value).Select(item => item.Key).ToArray(); return(new RewritedCacheRecord <TypeReference>(resolvedType, mappings)); }
private static TypeReference ResolveTypeReference(MethodReference method, TypeReference typeReference, Dictionary <GenericParameter, int> mappings) { var resolvedMethod = method.Resolve(); return(GenericTypesRewriter.ResolveTypeReference( typeReference, (tr, resolutionStack) => { if (tr is GenericParameter) { var gp = (GenericParameter)tr; if (resolutionStack.Count(typeInStack => TypeUtil.TypesAreEqual(typeInStack, gp)) > 1) { return GenericTypesRewriter.ReplaceWithGenericArgument(gp, mappings); } var result = MethodSignature.ResolveGenericParameter(gp, method.DeclaringType); if (result is GenericParameter) { gp = (GenericParameter)result; result = null; } if (result == null) { if (gp.Owner is MethodReference) { var mr = (MethodReference)gp.Owner; if (mr.Resolve() == resolvedMethod) { return gp; } } return GenericTypesRewriter.ReplaceWithGenericArgument(gp, mappings); } return result; } return tr; }, null)); }