public static IHttpActionResult GetOKHttpActionResult(ODataController controller, object propertyValue) { var okMethod = default(MethodInfo); var methods = controller.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); foreach (var method in methods) { if (method.Name == "Ok" && method.GetParameters().Length == 1) { okMethod = method; break; } } okMethod = okMethod.MakeGenericMethod(propertyValue.GetType()); var returnValue = okMethod.Invoke(controller, new object[] { propertyValue }); return (IHttpActionResult)returnValue; }
public static IHttpActionResult GetOKHttpActionResult(ODataController controller, object propertyValue) { var okMethod = default(MethodInfo); var methods = controller.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); foreach (var method in methods) { if (method.Name == "Ok" && method.GetParameters().Length == 1) { okMethod = method; break; } } okMethod = okMethod.MakeGenericMethod(propertyValue.GetType()); var returnValue = okMethod.Invoke(controller, new object[] { propertyValue }); return((IHttpActionResult)returnValue); }
public static IActionResult CreateOKHttpActionResult(this ODataController controller, object propertyValue) { var okMethod = default(MethodInfo); // find the ok method on the current controller var methods = controller.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); foreach (var method in methods) { if (method.Name == "Ok" && method.GetParameters().Length == 1) { okMethod = method; break; } } // invoke the method, passing in the propertyValue okMethod = okMethod.MakeGenericMethod(propertyValue.GetType()); var returnValue = okMethod.Invoke(controller, new object[] { propertyValue }); return((IActionResult)returnValue); }