Skip to content

Instantly share code, notes, and snippets.

@RyuaNerin
Created August 2, 2015 08:41
Show Gist options
  • Save RyuaNerin/497ccf5f4de2c1934e7e to your computer and use it in GitHub Desktop.
Save RyuaNerin/497ccf5f4de2c1934e7e to your computer and use it in GitHub Desktop.
MethodInfo 가 특정 delegate 랑 같은 형식인지 확인해주는거. Linq 가 필요하다
private static bool IsMethodCompatibleWithDelegate<T>(MethodInfo method) where T : class
{
return IsMethodCompatibleWithDelegate(method, typeof(T));
}
public static bool IsMethodCompatibleWithDelegate(MethodInfo method, Type delegateType)
{
MethodInfo invoke = delegateType.GetMethod("Invoke");
return invoke.ReturnType == method.ReturnType &&
invoke.GetParameters().Select(x => x.ParameterType)
.SequenceEqual(method.GetParameters().Select(x => x.ParameterType));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment