/// <summary> /// Gets the <see cref="MethodInfo" /> of the referenced port. /// </summary> internal MethodInfo GetMethod() { var method = DeclaringType .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly) .SingleOrDefault(m => m.Name == PortName && m.ReturnType == ReturnType && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(ArgumentTypes)); Requires.That(method != null, $"'{DeclaringType.FullName}' does not declare an instance method called '{PortName}' with the given signature."); // If the method is an interface method, we have to determine the actual method on the target object // that will be invoked, otherwise we wouldn't be able to find the binding field of required ports, for instance if (method.DeclaringType.IsInterface) { return(TargetObject.GetType().ResolveImplementingMethod(method)); } return(method); }