Browse Source

Backport the core helpers changes to OpenIddict 1.x

pull/670/head
Kévin Chalet 8 years ago
parent
commit
51b4e44b42
  1. 37
      src/OpenIddict.Core/OpenIddictCoreHelpers.cs

37
src/OpenIddict.Core/OpenIddictCoreHelpers.cs

@ -34,31 +34,34 @@ namespace OpenIddict.Core
throw new ArgumentException("The second parameter must be a generic type definition.", nameof(definition));
}
for (var candidate = type.GetTypeInfo(); candidate != null; candidate = candidate.BaseType?.GetTypeInfo())
if (definition.GetTypeInfo().IsInterface)
{
if (!candidate.IsGenericType && !candidate.AsType().IsConstructedGenericType)
foreach (var contract in type.GetInterfaces())
{
continue;
}
if (!contract.GetTypeInfo().IsGenericType && !contract.IsConstructedGenericType)
{
continue;
}
if (candidate.GetGenericTypeDefinition() == definition)
{
return candidate.AsType();
if (contract.GetGenericTypeDefinition() == definition)
{
return contract;
}
}
}
if (definition.GetTypeInfo().IsInterface)
else
{
for (var candidate = type; candidate != null; candidate = candidate.GetTypeInfo().BaseType)
{
foreach (var contract in candidate.AsType().GetInterfaces().Select(contract => contract.GetTypeInfo()))
if (!candidate.GetTypeInfo().IsGenericType && !candidate.IsConstructedGenericType)
{
if (!contract.IsGenericType && !contract.AsType().IsConstructedGenericType)
{
continue;
}
continue;
}
if (contract.GetGenericTypeDefinition() == definition)
{
return contract.AsType();
}
if (candidate.GetGenericTypeDefinition() == definition)
{
return candidate;
}
}
}

Loading…
Cancel
Save