From 8e981f25b6627cb5b2dd65c1e239ba04bbe66a4b Mon Sep 17 00:00:00 2001 From: dahall Date: Tue, 9 Jun 2020 19:00:42 -0600 Subject: [PATCH] Added IsMethodCompatibleWithDelegate method --- Core/Extensions/ReflectionExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Core/Extensions/ReflectionExtensions.cs b/Core/Extensions/ReflectionExtensions.cs index 90fe6d9e..470ee937 100644 --- a/Core/Extensions/ReflectionExtensions.cs +++ b/Core/Extensions/ReflectionExtensions.cs @@ -378,6 +378,16 @@ namespace Vanara.Extensions } #endif + /// Determines whether the specified method is compatible with a delegate. + /// The type of the delegate. + /// The method information. + /// if method is compatible with the delegate; otherwise, . + public static bool IsMethodCompatibleWithDelegate(this MethodInfo method) where TDel : Delegate + { + var delegateSignature = typeof(TDel).GetMethod("Invoke"); + return delegateSignature.ReturnType == method.ReturnType && delegateSignature.GetParameters().Select(x => x.ParameterType).SequenceEqual(method.GetParameters().Select(x => x.ParameterType)); + } + /// Loads a type from a named assembly. /// Name of the type. /// The name or path of the file that contains the manifest of the assembly.