예제 #1
0
        /// <inheritdoc/>
        internal override IEnumerable <TypeData> GetDirectImplicitConversions(bool onlyReferenceAndIdentityConversions)
        {
            if (onlyReferenceAndIdentityConversions == false)
            {
                var mscorlibData = AssemblyData.GetReferencedAssembly(Utilities.CommonObjectRuntimeAssemblyName);
                if (mscorlibData != null)
                {
                    if (TypeKind == TypeKind.Enum)
                    {
                        yield return(mscorlibData.GetTypeDefinitionData(Utilities.EnumTypeName));
                    }
                    else
                    {
                        // See if there is an implicit numeric conversion for the types.
                        if (mscorlibData != null &&
                            _implicitNumericConversions.TryGetValue(FullName, out HashSet <string> destTypeNames))
                        {
                            foreach (var numericTypeName in destTypeNames)
                            {
                                yield return(mscorlibData.GetTypeDefinitionData(numericTypeName));
                            }
                        }
                    }
                }
            }

            foreach (var item in base.GetDirectImplicitConversions(onlyReferenceAndIdentityConversions))
            {
                yield return(item);
            }
        }
        /// <inheritdoc/>
        internal override IEnumerable <TypeData> GetDirectImplicitConversions(bool onlyReferenceAndIdentityConversions)
        {
            if (onlyReferenceAndIdentityConversions && IsValueType)
            {
                yield break;
            }

            if (TypeKind != TypeKind.Enum && BaseType != null)
            {
                yield return(BaseType);
            }

            foreach (var implementedInterface in ImplementedInterfaces)
            {
                yield return(implementedInterface);
            }

            // Any interface type can convert to object
            if (TypeKind == TypeKind.Interface)
            {
                var mscorlibData = AssemblyData.GetReferencedAssembly(Utilities.CommonObjectRuntimeAssemblyName);
                if (mscorlibData != null)
                {
                    yield return(mscorlibData.GetTypeDefinitionData(Utilities.ObjectTypeName));
                }
            }
        }
예제 #3
0
        /// <inheritdoc/>
        internal override IEnumerable <TypeData> GetDirectImplicitConversions(bool onlyReferenceAndIdentityConversions)
        {
            if (onlyReferenceAndIdentityConversions && IsValueType)
            {
                yield break;
            }

            foreach (var constraint in Constraints)
            {
                yield return(constraint);
            }

            // Any generic type parameter can convert to object
            var mscorlibData = AssemblyData.GetReferencedAssembly(Utilities.CommonObjectRuntimeAssemblyName);

            if (mscorlibData != null)
            {
                yield return(mscorlibData.GetTypeDefinitionData(Utilities.ObjectTypeName));
            }
        }