From 9cd2ad15ff2a306bab9894dc7c1926c196b3fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 5 Jun 2019 19:58:54 +0200 Subject: [PATCH] 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. --- src/Shared/ObjectMethodExecutor/AwaitableInfo.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs index d53c986fd2..ef0daf4186 100644 --- a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs +++ b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs @@ -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