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

IsValidInstanceType() public static method

public static IsValidInstanceType ( MemberInfo member, Type instanceType ) : bool
member System.Reflection.MemberInfo
instanceType Type
return bool
        public static bool IsValidInstanceType(MemberInfo member, Type instanceType)
        {
            Type targetType = member.DeclaringType;
            if (AreReferenceAssignable(targetType, instanceType))
            {
                return true;
            }
            if (instanceType.GetTypeInfo().IsValueType)
            {
                if (AreReferenceAssignable(targetType, typeof(object)))
                {
                    return true;
                }
                if (AreReferenceAssignable(targetType, typeof(ValueType)))
                {
                    return true;
                }
                if (instanceType.GetTypeInfo().IsEnum && AreReferenceAssignable(targetType, typeof(Enum)))
                {
                    return true;
                }
                // A call to an interface implemented by a struct is legal whether the struct has
                // been boxed or not.
                if (targetType.GetTypeInfo().IsInterface)
                {
                    foreach (Type interfaceType in instanceType.GetTypeInfo().ImplementedInterfaces)
                    {
                        if (AreReferenceAssignable(targetType, interfaceType))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }