/// <summary> /// Get the MethodDesc that corresponds to an interface type/slot pair /// </summary> public static bool TryGetMethodFromInterfaceSlot(TypeDesc owningType, ushort slot, out MethodDesc method) { int iMethod = -1; method = null; // This is only valid to call on an interface if (!owningType.IsInterface) return false; // Slots on generic interface types are off by one. if (owningType.IsGeneric()) { if (slot == 0) throw new BadImageFormatException(); slot--; } foreach (MethodDesc searchMethod in owningType.GetMethods()) { if (searchMethod.IsVirtual) { iMethod++; if (iMethod == slot) { method = searchMethod; return true; } } } return false; }