Last active
December 11, 2015 01:58
-
-
Save filipw/4527112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MethodInfo GetMethodInfo<T, U>(Expression<Func<T, U>> expression) | |
{ | |
var method = expression.Body as MethodCallExpression; | |
if (method != null) | |
return method.Method; | |
throw new ArgumentException("Expression is wrong"); | |
} | |
public static MethodInfo GetMethodInfo<T, U>(Expression<Action<T>> expression) | |
{ | |
var method = expression.Body as MethodCallExpression; | |
if (method != null) | |
return method.Method; | |
throw new ArgumentException("Expression is wrong"); | |
} | |
//Then in the route tester you can add | |
public bool CompareSignatures(MethodInfo method) | |
{ | |
if (_controllerContext.ControllerDescriptor == null) | |
GetControllerType(); | |
var actionSelector = new ApiControllerActionSelector(); | |
var x = actionSelector.GetActionMapping(_controllerContext.ControllerDescriptor)[_request.Method.ToString()]; | |
return x.Any(item => ((MethodBase)(((ReflectedHttpActionDescriptor)item).MethodInfo)).ToString() == ((MethodBase)method).ToString()); | |
} | |
//usage | |
Assert.IsTrue(routeTester.CompareSignatures(ReflectionHelpers.GetMethodInfo((PersonController p) => p.Get()))); | |
Assert.IsTrue(routeTester.CompareSignatures(ReflectionHelpers.GetMethodInfo((PersonController p) => p.Get(new Guid("d39a7401-5ec7-4611-9934-fdcc1be0dc98"))))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment