Skip to content

Commit

Permalink
Fixed async methods invocation for internal api classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Izhovkin committed May 21, 2015
1 parent ac5ad3e commit 94c5c06
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Owin.Routing/ReflectionRouting.cs
Expand Up @@ -77,7 +77,7 @@ public static IAppBuilder UseApi<T>(this IAppBuilder app, Func<IOwinContext, T>
{
if (hasResult)
{
result = await (dynamic) result;
result = await ToTaskOfObject((Task) result);
}
else
{
Expand All @@ -94,6 +94,15 @@ public static IAppBuilder UseApi<T>(this IAppBuilder app, Func<IOwinContext, T>
return app;
}

private static Task<object> ToTaskOfObject(Task task)
{
return task.ContinueWith(t =>
{
var resultProp = task.GetType().GetProperty("Result", BindingFlags.Public | BindingFlags.Instance);

This comment has been minimized.

Copy link
@sergeyt

sergeyt May 21, 2015

using of "dynamic" could reduce code and maybe improve performance a bit for successive calls

This comment has been minimized.

Copy link
@izhovkin

izhovkin May 21, 2015

Owner

dynamic does not work when return type is internal. It throws exception with message like 'can not cast void to object'.
I have not found how to make it work with dynamic.

This comment has been minimized.

Copy link
@sergeyt

sergeyt May 21, 2015

Reflection is fine for internal case, and use fast code path with "dynamic" when result type is public. Also we could try to compile getter with expression tree to get "Result" property from result object.

return resultProp.GetValue(t);
});
}

private static object[] MapParameters(IOwinContext ctx, Func<IOwinContext, object[]> mapper, out string error)
{
error = null;
Expand Down

0 comments on commit 94c5c06

Please sign in to comment.