This commit is contained in:
Eugene Sadovoi 2019-04-09 22:51:37 -04:00
Родитель 48aaf64a7a
Коммит 53fd48355d
3 изменённых файлов: 67 добавлений и 3 удалений

Просмотреть файл

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using Unity.Registration;
using Unity.Resolution;
using Unity.Storage;
@ -14,6 +15,7 @@ namespace Unity
#endregion
#region Fields
private Registry _registry;
@ -150,6 +152,68 @@ namespace Unity
}
}
#endregion
#region Verification
internal bool RegistrationExists(ref NamedType key)
{
var hashCode = key.GetHashCode() & 0x7FFFFFFF;
Type type = null;
#if NETSTANDARD1_0 || NETCOREAPP1_0
var info = key.Type.GetTypeInfo();
if (info.IsGenericType) type = info.GetGenericTypeDefinition();
#else
if (key.Type.IsGenericType) type = key.Type.GetGenericTypeDefinition();
#endif
// Iterate through containers hierarchy
for (var container = this; null != container; container = container._parent)
{
var registry = container._registry;
if (null == registry) continue;
// Look for exact match
var targetBucket = hashCode % registry.Buckets.Length;
for (var i = registry.Buckets[targetBucket]; i >= 0; i = registry.Entries[i].Next)
{
ref var candidate = ref registry.Entries[i];
if (candidate.HashCode != hashCode ||
candidate.Key.Type != key.Type)
{
continue;
}
return true; // Found a registration
}
if (null == type) continue;
var metadate = container._metadata;
// Look for generic factory
targetBucket = hashCode % metadate.Buckets.Length;
for (var i = metadate.Buckets[targetBucket]; i >= 0; i = metadate.Entries[i].Next)
{
ref var candidate = ref registry.Entries[i];
if (candidate.HashCode != hashCode ||
candidate.Key.Type != key.Type)
{
continue;
}
return true; // Found a registration
}
}
return false;
}
#endregion
}
}

Просмотреть файл

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

Просмотреть файл

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>