Browse Source

Rework OpenIddictCoreHelpers.FindGenericBaseType()

pull/596/head
Kévin Chalet 8 years ago
parent
commit
6104cd8f9e
  1. 37
      src/OpenIddict.Core/OpenIddictCoreHelpers.cs

37
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;
}
}
}

Loading…
Cancel
Save