/// <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; }
/// <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); }
public bool Equals(TypeDataSequence other) { if (_types.Length != other._types.Length) { return(false); } for (int i = 0; i < _types.Length; i++) { if (_types[i] != other._types[i]) { return(false); } } return(true); }
/// <summary> /// Gets the types to which this type can implicitly convert. For type hierarchy conversions, only the direct base type will be enumerated. /// Ancestor base types will can be enumerated recursively by calling this method on the base type. /// </summary> /// <param name="onlyReferenceAndIdentityConversions"> /// True if reference and identify conversions are they only allowed conversions; False if all implicit conversions are allowed. /// </param> /// <returns> /// A collection of all types to which this type can convert explicitly, except for ancestor base types which are not the direct base type. /// </returns> #endif internal override IEnumerable <TypeData> GetDirectImplicitConversions(bool onlyReferenceAndIdentityConversions) { var mscorlibData = this.AssemblyData.GetReferencedAssembly(Utilities.CommonObjectRuntimeAssemblyName); if (mscorlibData == null) { yield break; } yield return(mscorlibData.GetTypeDefinitionData(Utilities.ArrayTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.ICloneableTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IListTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.ICollectionTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IEnumerableTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IStructuralComparableTypeName)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IStructuralEquatableTypeName)); if (this.ArrayRank == 1) { var genericArguments = new TypeDataSequence(this.ElementType); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IListGenericTypeName).GetConstructedGenericTypeData(genericArguments)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.ICollectionGenericTypeName).GetConstructedGenericTypeData(genericArguments)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IEnumerableGenericTypeName).GetConstructedGenericTypeData(genericArguments)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IReadOnlyCollectionGenericTypeName).GetConstructedGenericTypeData(genericArguments)); yield return(mscorlibData.GetTypeDefinitionData(Utilities.IReadOnlyListGenericTypeName).GetConstructedGenericTypeData(genericArguments)); } }