Example #1
0
        private bool QuickSerializationCastCheck()
        {
            ITypeUniverse typeUniverse  = Helpers.Universe(this);
            Type          typeXFromName = typeUniverse.GetTypeXFromName("System.Enum");
            Type          type          = typeUniverse.GetTypeXFromName("System.Delegate");

            for (Type i = this.UnderlyingSystemType; i != null; i = i.BaseType)
            {
                if (i.Equals(typeXFromName) || i.Equals(type))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        internal static bool IsAssignableFromHelper(Type current, Type target)
        {
            if (target == null)
            {
                return(false);
            }
            if (current.Equals(target))
            {
                return(true);
            }
            if (target.IsSubclassOf(current))
            {
                return(true);
            }
            Type[] interfaces = target.GetInterfaces();
            for (int i = 0; i < (int)interfaces.Length; i++)
            {
                if (interfaces[i].Equals(current))
                {
                    return(true);
                }
                if (current.IsAssignableFrom(interfaces[i]))
                {
                    return(true);
                }
            }
            if (target.IsGenericParameter)
            {
                Type[] genericParameterConstraints = target.GetGenericParameterConstraints();
                for (int j = 0; j < (int)genericParameterConstraints.Length; j++)
                {
                    if (MetadataOnlyTypeDef.IsAssignableFromHelper(current, genericParameterConstraints[j]))
                    {
                        return(true);
                    }
                }
            }
            ITypeUniverse typeUniverse = Helpers.Universe(current);

            if (typeUniverse == null || !current.Equals(typeUniverse.GetTypeXFromName("System.Object")))
            {
                return(false);
            }
            if (target.IsPointer || target.IsInterface)
            {
                return(true);
            }
            return(target.IsArray);
        }