protected virtual void AppendReflectedMethod(StringBuilder builder, AstReflectedMethod reflectedMethod) { builder.Append(reflectedMethod); }
private int GetDistanceForAll(AstReflectedMethod reflected, IEnumerable<Type> parameterTypes, IEnumerable<Type> argumentTypes, IDictionary<Type, ISet<Type>> genericTheories) { var totalDistance = 0; using (var parameterTypeEnumerator = parameterTypes.GetEnumerator()) using (var argumentTypeEnumerator = argumentTypes.GetEnumerator()) { while (parameterTypeEnumerator.MoveNext()) { if (!argumentTypeEnumerator.MoveNext()) return -1; var distance = GetDistance(parameterTypeEnumerator.Current, argumentTypeEnumerator.Current, reflected, genericTheories); if (distance == -1) return -1; totalDistance += distance; } if (argumentTypeEnumerator.MoveNext()) return -1; } return totalDistance; }
private Tuple<IAstMethodReference, int> GetOrMakeMatch(AstReflectedMethod reflected, IEnumerable<Type> parameterTypes, IEnumerable<Type> argumentTypes) { var genericTheories = new Dictionary<Type, ISet<Type>>(); var distance = GetDistanceForAll(reflected, parameterTypes, argumentTypes, genericTheories); if (distance == -1) return null; if (reflected.Method.IsGenericMethodDefinition) { var genericParameters = reflected.Method.GetGenericArguments(); var genericArguments = new Type[genericParameters.Length]; for (var i = 0; i < genericParameters.Length; i++) { var theories = genericTheories.GetValueOrDefault(genericParameters[i]); if (theories == null) return null; var aggregate = ReconcileGenericTheories(theories); if (aggregate == null) return null; genericArguments[i] = aggregate; } var generic = reflected.Method.MakeGenericMethod(genericArguments); return Tuple.Create((IAstMethodReference)new AstReflectedMethod(generic), distance); } return Tuple.Create((IAstMethodReference)reflected, distance); }
private int GetDistance(Type parameterType, Type argumentType, AstReflectedMethod reflected, IDictionary<Type, ISet<Type>> genericTheories) { var argumentCompatibleTypes = GetCompatibleTypes(argumentType); var distance = argumentCompatibleTypes.GetValueOrDefault(parameterType, -1); if (distance != -1) return distance; if (!reflected.Method.IsGenericMethodDefinition) return -1; if (CanMatchPotentialGeneric(parameterType, argumentType, argumentCompatibleTypes, genericTheories)) return 0; return -1; }