Beispiel #1
0
        public virtual bool IsAssignableFrom(TypeInfo typeInfo)
        {
            if (typeInfo == null)
                return false;

            if (this == typeInfo)
                return true;

            // If c is a subclass of this class, then c can be cast to this type.
            if (typeInfo.IsSubclassOf(this))
                return true;

            if (this.IsInterface)
            {
                return typeInfo.ImplementInterface(this);
            }
            else if (IsGenericParameter)
            {
                Type[] constraints = GetGenericParameterConstraints();
                for (int i = 0; i < constraints.Length; i++)
                    if (!constraints[i].IsAssignableFrom(typeInfo))
                        return false;

                return true;
            }

            return false;
        }
 public virtual bool IsAssignableFrom(TypeInfo typeInfo)
 {
     if (typeInfo == null)
     {
         return(false);
     }
     if (this == typeInfo)
     {
         return(true);
     }
     if (typeInfo.IsSubclassOf(this))
     {
         return(true);
     }
     if (base.IsInterface)
     {
         return(typeInfo.ImplementInterface(this));
     }
     if (this.IsGenericParameter)
     {
         Type[] genericParameterConstraints = this.GetGenericParameterConstraints();
         for (int i = 0; i < genericParameterConstraints.Length; i++)
         {
             if (!genericParameterConstraints[i].IsAssignableFrom(typeInfo))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 public virtual bool IsAssignableFrom(TypeInfo typeInfo)
 {
     if ((Type)typeInfo == (Type)null)
     {
         return(false);
     }
     if ((Type)this == (Type)typeInfo || typeInfo.IsSubclassOf((Type)this))
     {
         return(true);
     }
     if (this.IsInterface)
     {
         return(typeInfo.ImplementInterface((Type)this));
     }
     if (!this.IsGenericParameter)
     {
         return(false);
     }
     foreach (Type parameterConstraint in this.GetGenericParameterConstraints())
     {
         if (!parameterConstraint.IsAssignableFrom((Type)typeInfo))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #4
0
        //a re-implementation of ISAF from Type, skipping the use of UnderlyingType
        public virtual bool IsAssignableFrom(TypeInfo typeInfo)
        {
            if (typeInfo == null)
            {
                return(false);
            }

            if (this == typeInfo)
            {
                return(true);
            }

            // If c is a subclass of this class, then c can be cast to this type.
            if (typeInfo.IsSubclassOf(this))
            {
                return(true);
            }

            if (this.IsInterface)
            {
                return(typeInfo.ImplementInterface(this));
            }
            else if (IsGenericParameter)
            {
                Type[] constraints = GetGenericParameterConstraints();
                for (int i = 0; i < constraints.Length; i++)
                {
                    if (!constraints[i].IsAssignableFrom(typeInfo))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }