private bool HasImplicitReferenceTypeParameterConversion( TypeParameterType pSource, CType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (!pSource.IsRefType()) { // Not a reference conversion. return(false); } // The following implicit conversions exist for a given type parameter T: // // * From T to its effective base class C. AggregateType pEBC = pSource.GetEffectiveBaseClass(); if (pDest == pEBC) { return(true); } // * From T to any base class of C. if (IsBaseClass(pEBC, pDest)) { return(true); } // * From T to any interface implemented by C. if (IsBaseInterface(pEBC, pDest)) { return(true); } // * From T to any interface type I in T's effective interface set, and // from T to any base interface of I. TypeArray pInterfaces = pSource.GetInterfaceBounds(); for (int i = 0; i < pInterfaces.Count; ++i) { if (pInterfaces[i] == pDest) { return(true); } } // * From T to a type parameter U, provided T depends on U. if (pDest.IsTypeParameterType() && pSource.DependsOn(pDest.AsTypeParameterType())) { return(true); } return(false); }
private bool HasImplicitBoxingTypeParameterConversion( TypeParameterType pSource, CType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (pSource.IsRefType()) { // Not a boxing conversion; both source and destination are references. return(false); } // The following implicit conversions exist for a given type parameter T: // // * From T to its effective base class C. AggregateType pEBC = pSource.GetEffectiveBaseClass(); if (pDest == pEBC) { return(true); } // * From T to any base class of C. if (IsBaseClass(pEBC, pDest)) { return(true); } // * From T to any interface implemented by C. if (IsBaseInterface(pEBC, pDest)) { return(true); } // * From T to any interface type I in T's effective interface set, and // from T to any base interface of I. TypeArray pInterfaces = pSource.GetInterfaceBounds(); for (int i = 0; i < pInterfaces.Count; ++i) { if (pInterfaces[i] == pDest) { return(true); } } // * The conversion from T to a type parameter U, provided T depends on U, is not // classified as a boxing conversion because it is not guaranteed to box. // (If both T and U are value types then it is an identity conversion.) return(false); }
private bool HasImplicitBoxingTypeParameterConversion( TypeParameterType pSource, CType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (pSource.IsRefType()) { // Not a boxing conversion; both source and destination are references. return false; } // The following implicit conversions exist for a given type parameter T: // // * From T to its effective base class C. AggregateType pEBC = pSource.GetEffectiveBaseClass(); if (pDest == pEBC) { return true; } // * From T to any base class of C. if (IsBaseClass(pEBC, pDest)) { return true; } // * From T to any interface implemented by C. if (IsBaseInterface(pEBC, pDest)) { return true; } // * From T to any interface type I in T's effective interface set, and // from T to any base interface of I. TypeArray pInterfaces = pSource.GetInterfaceBounds(); for (int i = 0; i < pInterfaces.Size; ++i) { if (pInterfaces.Item(i) == pDest) { return true; } } // * The conversion from T to a type parameter U, provided T depends on U, is not // classified as a boxing conversion because it is not guaranteed to box. // (If both T and U are value types then it is an identity conversion.) return false; }
private bool HasImplicitReferenceTypeParameterConversion( TypeParameterType pSource, CType pDest) { Debug.Assert(pSource != null); Debug.Assert(pDest != null); if (!pSource.IsRefType()) { // Not a reference conversion. return false; } // The following implicit conversions exist for a given type parameter T: // // * From T to its effective base class C. AggregateType pEBC = pSource.GetEffectiveBaseClass(); if (pDest == pEBC) { return true; } // * From T to any base class of C. if (IsBaseClass(pEBC, pDest)) { return true; } // * From T to any interface implemented by C. if (IsBaseInterface(pEBC, pDest)) { return true; } // * From T to any interface type I in T's effective interface set, and // from T to any base interface of I. TypeArray pInterfaces = pSource.GetInterfaceBounds(); for (int i = 0; i < pInterfaces.Size; ++i) { if (pInterfaces.Item(i) == pDest) { return true; } } // * From T to a type parameter U, provided T depends on U. if (pDest.IsTypeParameterType() && pSource.DependsOn(pDest.AsTypeParameterType())) { return true; } return false; }