Beispiel #1
0
 internal void RegisterForFinalize(ConstructedGenericTypeData type)
 {
     if (_isLoading)
     {
         _constructedGenericsToFinalizeAfterLoad.Add(type);
     }
     else
     {
         type.FinalizeDefiniton();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Registers a <see cref="ConstructedGenericTypeData"/> instance with the current type as its generic type definition so it can be cached and re-used when trying
        /// to get a constructed generic type with the same type arguments.
        /// </summary>
#endif
        internal void RegisterConstructedGenericTypeData(ConstructedGenericTypeData constructedGenericType)
        {
            Debug.Assert(this.GenericParameters == null || this.GenericParameters.Count == constructedGenericType.GenericArguments.Count, "The type arity does not match.");

            if (_constructedGenericTypes == null)
            {
                _constructedGenericTypes = new Dictionary <TypeDataSequence, ConstructedGenericTypeData>();
            }

            var key = new TypeDataSequence(constructedGenericType.GenericArguments);

            Debug.Assert(_constructedGenericTypes.ContainsKey(key) == false, "We should not register the same constructed generic twice.");
            _constructedGenericTypes[key] = constructedGenericType;
        }
Beispiel #3
0
        /// <summary>
        /// Gets a <see cref="ConstructedGenericTypeData"/> instance with the current type as its generic type definition and the specified sequence of type as its
        /// generic type arguments.
        /// </summary>
        internal ConstructedGenericTypeData GetConstructedGenericTypeData(TypeDataSequence typeArguments)
        {
            Debug.Assert(GenericParameters == null || GenericParameters.Count == typeArguments.Count, "The type arity does not match.");

            if (_constructedGenericTypes == null)
            {
                _constructedGenericTypes = new Dictionary <TypeDataSequence, ConstructedGenericTypeData>();
            }

            if (_constructedGenericTypes.TryGetValue(typeArguments, out ConstructedGenericTypeData constructedGenericType) == false)
            {
                constructedGenericType = new ConstructedGenericTypeData(this, typeArguments);
                Debug.Assert(_constructedGenericTypes.ContainsKey(typeArguments), "The constructed generic type did not register itself.");
            }

            return(constructedGenericType);
        }
Beispiel #4
0
        /// <inheritdoc/>
        internal override bool IsVarianceConvertibleTo(ConstructedGenericTypeData target, IsAssignableFromContext context)
        {
            if (target.TypeKind == TypeKind &&
                target.GenericTypeDefinition == GenericTypeDefinition &&
                target.GenericArguments.Count == GenericArguments.Count)
            {
                Debug.Assert(
                    target.GenericArguments.Count == GenericArguments.Count,
                    "Two constructed generic types from the same generic type definition should have the same number of generic arguments.");

                var genericParameters = target.GenericTypeDefinition.GenericParameters;
                for (int i = 0, count = genericParameters.Count; i < count; i++)
                {
                    if (genericParameters[i].IsGenericTypeArgumentVariant(target.GenericArguments[i], GenericArguments[i], context) == false)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Indicates whether the type can convert to the specified target type using type parameter variance.
        /// </summary>
        /// <param name="target">The target type to which this type might convert.</param>
        /// <param name="context">Information about the context of the IsAssignableFrom invocation.</param>
        /// <returns>True is the type is variance convertible to the target; False otherwise.</returns>
#endif
        internal virtual bool IsVarianceConvertibleTo(ConstructedGenericTypeData target, IsAssignableFromContext context)
        {
            return(false);
        }
Beispiel #6
0
 /// <summary>
 /// Gets the derived <see cref="ConstructedGenericTypeData"/> instance representing the specified type.
 /// </summary>
 /// <typeparam name="T">The type for which to get the <see cref="ConstructedGenericTypeData"/>.</typeparam>
 /// <returns>The derived <see cref="ConstructedGenericTypeData"/> instance.</returns>
 public new static ConstructedGenericTypeData FromType <T>()
 {
     return(ConstructedGenericTypeData.FromType(typeof(T)));
 }
 /// <summary>
 /// The visit implementation for <see cref="ConstructedGenericTypeData"/> instances.
 /// </summary>
 public virtual void VisitConstructedGenericTypeData(ConstructedGenericTypeData item)
 {
     this.DefaultVisit(item);
 }