Exemplo n.º 1
0
        __CastResult __CanCastToClassNoGC(DmdType target)
        {
            if (target.__HasVariance())
            {
                return(__CastResult.MaybeCast);
            }

            if (HasTypeEquivalence || target.HasTypeEquivalence)
            {
                return(__CastResult.MaybeCast);
            }
            else
            {
                var type = this;
                for (int i = 0; i < 1000; i++)
                {
                    if (type == target)
                    {
                        return(__CastResult.CanCast);
                    }

                    type = type.BaseType;
                    if ((object)type == null)
                    {
                        break;
                    }
                }
            }

            return(__CastResult.CannotCast);
        }
Exemplo n.º 2
0
 __CastResult __CanCastToInterfaceNoGC(DmdType target)
 {
     if (!target.__HasVariance() && !IsArray && !HasTypeEquivalence && !target.HasTypeEquivalence)
     {
         return(__CanCastToNonVariantInterface(target) ? __CastResult.CanCast : __CastResult.CannotCast);
     }
     return(__CastResult.MaybeCast);
 }
Exemplo n.º 3
0
        bool __CanCastToClass(DmdType pTargetMT)
        {
            var type = this;

            if (pTargetMT.__HasVariance())
            {
                for (int i = 0; i < 1000; i++)
                {
                    if (type.IsEquivalentTo(pTargetMT))
                    {
                        return(true);
                    }

                    if (type.__CanCastByVarianceToInterfaceOrDelegate(pTargetMT))
                    {
                        return(true);
                    }

                    type = type.BaseType;
                    if ((object)type == null)
                    {
                        break;
                    }
                }
            }

            else
            {
                for (int i = 0; i < 1000; i++)
                {
                    if (type.IsEquivalentTo(pTargetMT))
                    {
                        return(true);
                    }

                    type = type.BaseType;
                    if ((object)type == null)
                    {
                        break;
                    }
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        bool __CanCastToInterface(DmdType target)
        {
            if (!target.__HasVariance())
            {
                if (HasTypeEquivalence || target.HasTypeEquivalence)
                {
                    if (IsInterface && IsEquivalentTo(target))
                    {
                        return(true);
                    }

                    return(__ImplementsEquivalentInterface(target));
                }

                return(__CanCastToNonVariantInterface(target));
            }
            else
            {
                if (__CanCastByVarianceToInterfaceOrDelegate(target))
                {
                    return(true);
                }

                var hash = GetAllInterfaces(this);
                foreach (var iface in hash)
                {
                    if (iface.__CanCastByVarianceToInterfaceOrDelegate(target))
                    {
                        ObjectPools.Free(ref hash);
                        return(true);
                    }
                }
                ObjectPools.Free(ref hash);
            }
            return(false);
        }