private MethodDefinition GetMethodDefinition(IEnumerable <MethodDefinition> methods, MethodReference reference) { foreach (var methodDefinition in methods) { bool isSameName = methodDefinition.Name == reference.Name || MethodAliases.AreAliases(methodDefinition.Name, reference.Name); bool isSameGenericParameters = methodDefinition.HasGenericParameters == reference.HasGenericParameters && (!methodDefinition.HasGenericParameters || methodDefinition.GenericParameters.Count == reference.GenericParameters.Count); bool isSameReturnType = AreSame(methodDefinition.ReturnType, reference.ReturnType); if (isSameName && isSameGenericParameters && isSameReturnType && methodDefinition.HasParameters == reference.HasParameters) { if (!methodDefinition.HasParameters && !reference.HasParameters) { return(methodDefinition); } if (AreSame(methodDefinition.Parameters, reference.Parameters)) { return(methodDefinition); } } } return(null); }
private MethodDefinition GetCompatibleMethodDefinition(IEnumerable <MethodDefinition> methods, MethodReference reference) { foreach (var methodDefinition in methods) { bool isSameName = methodDefinition.Name == reference.Name || MethodAliases.AreAliases(methodDefinition.Name, reference.Name); bool isSameGenericParameters = methodDefinition.HasGenericParameters == reference.HasGenericParameters && (!methodDefinition.HasGenericParameters || methodDefinition.GenericParameters.Count == reference.GenericParameters.Count); bool isSameReturnType = AreSame(methodDefinition.ReturnType, reference.ReturnType); if (isSameName && isSameGenericParameters && isSameReturnType) { if (ArgsMatchParamsList(methodDefinition.Parameters, reference.Parameters)) { ParamsMethod = Context.TargetModule.Import(methodDefinition); MethodChanged = true; Context.RewriteTarget = true; return(methodDefinition); } } } return(null); }