From 6104cd8f9ed5df27d549e96bf0d251574d213524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 29 Apr 2018 15:24:05 +0200 Subject: [PATCH] Rework OpenIddictCoreHelpers.FindGenericBaseType() --- src/OpenIddict.Core/OpenIddictCoreHelpers.cs | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/OpenIddict.Core/OpenIddictCoreHelpers.cs b/src/OpenIddict.Core/OpenIddictCoreHelpers.cs index 75d3c541..ee5f43aa 100644 --- a/src/OpenIddict.Core/OpenIddictCoreHelpers.cs +++ b/src/OpenIddict.Core/OpenIddictCoreHelpers.cs @@ -32,31 +32,34 @@ namespace OpenIddict.Core throw new ArgumentException("The second parameter must be a generic type definition.", nameof(definition)); } - for (var candidate = type; candidate != null; candidate = candidate.BaseType) + if (definition.IsInterface) { - if (!candidate.IsGenericType && !candidate.IsConstructedGenericType) + foreach (var contract in type.GetInterfaces()) { - continue; - } + if (!contract.IsGenericType && !contract.IsConstructedGenericType) + { + continue; + } - if (candidate.GetGenericTypeDefinition() == definition) - { - return candidate; + if (contract.GetGenericTypeDefinition() == definition) + { + return contract; + } } + } - if (definition.IsInterface) + else + { + for (var candidate = type; candidate != null; candidate = candidate.BaseType) { - foreach (var contract in candidate.GetInterfaces()) + if (!candidate.IsGenericType && !candidate.IsConstructedGenericType) { - if (!contract.IsGenericType && !contract.IsConstructedGenericType) - { - continue; - } + continue; + } - if (contract.GetGenericTypeDefinition() == definition) - { - return contract; - } + if (candidate.GetGenericTypeDefinition() == definition) + { + return candidate; } } }