static bool IsParameterCompatibleWith(TypeSpecification a, TypeSpecification b, TypeDefinitionCache cache) { if (a is GenericInstanceType) { return(IsParameterCompatibleWith((GenericInstanceType)a, (GenericInstanceType)b, cache)); } if (a is IModifierType) { return(IsParameterCompatibleWith((IModifierType)a, (IModifierType)b, cache)); } return(IsParameterCompatibleWith(a.ElementType, b.ElementType, cache)); }
public static bool AreParametersCompatibleWith(this Collection <ParameterDefinition> a, Collection <ParameterDefinition> b, TypeDefinitionCache cache) { if (a.Count != b.Count) { return(false); } if (a.Count == 0) { return(true); } for (int i = 0; i < a.Count; i++) { if (!IsParameterCompatibleWith(a [i].ParameterType, b [i].ParameterType, cache)) { return(false); } } return(true); }
public static MethodDefinition GetBaseDefinition(this MethodDefinition method, TypeDefinitionCache cache) { if (method.IsStatic || method.IsNewSlot || !method.IsVirtual) { return(method); } foreach (var baseType in method.DeclaringType.GetBaseTypes(cache)) { foreach (var m in baseType.Methods) { if (!m.IsConstructor && m.Name == method.Name && (m.IsVirtual || m.IsAbstract) && AreParametersCompatibleWith(m.Parameters, method.Parameters, cache)) { return(m); } } } return(method); }
public static IEnumerable <MethodDefinition> GetOverriddenMethods(MethodDefinition method, bool inherit, TypeDefinitionCache cache) { yield return(method); if (inherit) { MethodDefinition baseMethod = method; while ((baseMethod = method.GetBaseDefinition(cache)) != null && baseMethod != method) { yield return(method); method = baseMethod; } } }
static bool IsParameterCompatibleWith(GenericInstanceType a, GenericInstanceType b, TypeDefinitionCache cache) { if (!IsParameterCompatibleWith(a.ElementType, b.ElementType, cache)) { return(false); } if (a.GenericArguments.Count != b.GenericArguments.Count) { return(false); } if (a.GenericArguments.Count == 0) { return(true); } for (int i = 0; i < a.GenericArguments.Count; i++) { if (!IsParameterCompatibleWith(a.GenericArguments [i], b.GenericArguments [i], cache)) { return(false); } } return(true); }