internal Type GetInstanceTypeBasedOnTargetGenericConstrains(Type targetType) { var registeredGenericTypeParameters = new Type[_registeredGenericTypeParameters.Length]; Array.Copy(_registeredGenericTypeParameters, registeredGenericTypeParameters, _registeredGenericTypeParameters.Length); var resolvingTypeDescriptor = targetType.Descriptor(); var resolvingTypeDefinitionDescriptor = resolvingTypeDescriptor.GetGenericTypeDefinition().Descriptor(); var resolvingTypeDefinitionGenericTypeParameters = resolvingTypeDefinitionDescriptor.GetGenericTypeParameters(); var constraintsMap = resolvingTypeDescriptor .GetGenericTypeArguments() .Zip(resolvingTypeDefinitionGenericTypeParameters, (type, typeDefinition) => Tuple.Create(type, typeDefinition.Descriptor().GetGenericParameterConstraints())) .ToArray(); var canBeResolved = true; foreach (var item in _genericParamsWithConstraints) { var position = item.Key; var descriptor = item.Value; var constraints = descriptor.GetGenericParameterConstraints(); var isDefined = false; foreach (var constraintsEntry in constraintsMap) { if (!CoreExtensions.SequenceEqual(constraints, constraintsEntry.Item2)) { continue; } registeredGenericTypeParameters[position] = constraintsEntry.Item1; isDefined = true; break; } if (!isDefined) { canBeResolved = false; break; } } return(canBeResolved ? _registeredTypeDescriptor.MakeGenericType(registeredGenericTypeParameters) : null); }
// ReSharper disable once PossibleNullReferenceException public override bool Equals(object obj) => CoreExtensions.SequenceEqual(_genericTypes, ((LifetimeKey)obj)._genericTypes);
private Bucket(int count) { KeyValues = CoreExtensions.CreateArray <KeyValue>(count); }
public bool Equals(LifetimeKey other) => CoreExtensions.SequenceEqual(_genericTypes, other._genericTypes);
private Bucket(KeyValue[] keyValues) { KeyValues = keyValues.Length == 0 ? CoreExtensions.EmptyArray <KeyValue>() : keyValues.Copy(); }