/// <summary>Applies the method patch using the specified <paramref name="patcher"/>.</summary> /// <param name="patcher">The patcher object that can perform the patching.</param> /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception> /// <exception cref="InvalidOperationException"> /// Thrown when no method for patching can be determined, or both the 'Prefix' and 'Postfix' methods are missing /// in the derived type. /// </exception> void IPatch.ApplyPatch(IPatcher patcher) { if (patcher == null) { throw new ArgumentNullException(nameof(patcher)); } if (method == null) { method = GetMethod(); } else { return; } if (method == null) { throw new InvalidOperationException("No method specified for patching"); } MethodInfo prefix = GetType().GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo postfix = GetType().GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic); if (prefix == null && postfix == null) { throw new InvalidOperationException("At least one of the 'Prefix' and 'Postfix' methods must be defined"); } patcher.ApplyPatch(method, prefix, postfix); }