Remove use of GetRuntimeInterfaceMap in IsTypeAwaitable (#10572)

`GetRuntimeInterfaceMap` is a rather expensive API and it doesn't look like the use here is warranted.

The replacement should have equivalent behavior.
This commit is contained in:
Michal Strehovský 2019-06-05 19:58:54 +02:00 committed by David Fowler
parent d1138f2cde
commit 9cd2ad15ff
1 changed files with 2 additions and 8 deletions

View File

@ -74,10 +74,7 @@ namespace Microsoft.Extensions.Internal
}
// INotifyCompletion supplies a method matching "void OnCompleted(Action action)"
var iNotifyCompletionMap = awaiterType
.GetTypeInfo()
.GetRuntimeInterfaceMap(typeof(INotifyCompletion));
var onCompletedMethod = iNotifyCompletionMap.InterfaceMethods.Single(m =>
var onCompletedMethod = typeof(INotifyCompletion).GetRuntimeMethods().Single(m =>
m.Name.Equals("OnCompleted", StringComparison.OrdinalIgnoreCase)
&& m.ReturnType == typeof(void)
&& m.GetParameters().Length == 1
@ -89,10 +86,7 @@ namespace Microsoft.Extensions.Internal
if (implementsICriticalNotifyCompletion)
{
// ICriticalNotifyCompletion supplies a method matching "void UnsafeOnCompleted(Action action)"
var iCriticalNotifyCompletionMap = awaiterType
.GetTypeInfo()
.GetRuntimeInterfaceMap(typeof(ICriticalNotifyCompletion));
unsafeOnCompletedMethod = iCriticalNotifyCompletionMap.InterfaceMethods.Single(m =>
unsafeOnCompletedMethod = typeof(ICriticalNotifyCompletion).GetRuntimeMethods().Single(m =>
m.Name.Equals("UnsafeOnCompleted", StringComparison.OrdinalIgnoreCase)
&& m.ReturnType == typeof(void)
&& m.GetParameters().Length == 1