System.Dynamic.Utils.TypeUtils.HasReferenceConversionTo C# (CSharp) Method

HasReferenceConversionTo() public static method

public static HasReferenceConversionTo ( this source, Type dest ) : bool
source this
dest Type
return bool
        public static bool HasReferenceConversionTo(this Type source, Type dest)
        {
            Debug.Assert(source != null && dest != null);

            // void -> void conversion is handled elsewhere
            // (it's an identity conversion)
            // All other void conversions are disallowed.
            if (source == typeof(void) || dest == typeof(void))
            {
                return false;
            }

            Type nnSourceType = GetNonNullableType(source);
            Type nnDestType = GetNonNullableType(dest);

            // Down conversion
            if (nnSourceType.GetTypeInfo().IsAssignableFrom(nnDestType.GetTypeInfo()))
            {
                return true;
            }
            // Up conversion
            if (nnDestType.GetTypeInfo().IsAssignableFrom(nnSourceType.GetTypeInfo()))
            {
                return true;
            }
            // Interface conversion
            if (source.GetTypeInfo().IsInterface || dest.GetTypeInfo().IsInterface)
            {
                return true;
            }
            // Variant delegate conversion
            if (IsLegalExplicitVariantDelegateConversion(source, dest))
                return true;

            // Object conversion
            if (source == typeof(object) || dest == typeof(object))
            {
                return true;
            }
            return false;
        }