예제 #1
0
파일: Nodes.cs 프로젝트: modulexcite/SHFB-1
 /// <summary>
 /// Returns true if this type is assignable to some instance of the given template.
 /// </summary>
 public virtual bool IsAssignableToInstanceOf(TypeNode targetTemplate)
 {
     if(this == CoreSystemTypes.Void || targetTemplate == null)
         return false;
     if(targetTemplate.IsStructurallyEquivalentTo(this.Template == null ? this : this.Template) ||
       this.BaseType != null && (this.BaseType.IsAssignableToInstanceOf(targetTemplate) ||
       this.BaseType.Template != null && this.BaseType.Template.IsAssignableToInstanceOf(targetTemplate)))
         return true;
     InterfaceList interfaces = this.Interfaces;
     if(interfaces == null)
         return false;
     for(int i = 0, n = interfaces.Count; i < n; i++)
     {
         Interface iface = interfaces[i];
         if(iface == null)
             continue;
         if(iface.IsAssignableToInstanceOf(targetTemplate))
             return true;
     }
     return false;
 }
예제 #2
0
        private static bool TypeMatch(TypeNode type1, TypeNode type2) {

            // the two types must be of the same kind
            if (type1.NodeType != type2.NodeType) return (false);

            if (type1.NodeType == NodeType.ArrayType) {
                // they are arrays, so check elements
                ArrayType array1 = (ArrayType)type1;
                ArrayType array2 = (ArrayType)type2;
                return (TypeMatch(array1.ElementType, array2.ElementType));
            } else {
                // they are normal types
                return (type1.IsStructurallyEquivalentTo(type2));
            }
        }
예제 #3
0
파일: Nodes.cs 프로젝트: modulexcite/SHFB-1
 public virtual Method GetImplicitCoercionFromMethod(TypeNode sourceType)
 {
     if(sourceType == null)
         return null;
     Method result = null;
     if(this.implicitCoercionFromTable != null)
         result = (Method)this.implicitCoercionFromTable[sourceType.UniqueKey];
     if(result == TypeNode.MethodDoesNotExist)
         return null;
     if(result != null)
         return result;
     lock(this)
     {
         if(this.implicitCoercionFromTable != null)
             result = (Method)this.implicitCoercionFromTable[sourceType.UniqueKey];
         if(result == TypeNode.MethodDoesNotExist)
             return null;
         if(result != null)
             return result;
         MemberList coercions = this.ImplicitCoercionMethods;
         for(int i = 0, n = coercions.Count; i < n; i++)
         {
             Method m = (Method)coercions[i];
             if(sourceType.IsStructurallyEquivalentTo(TypeNode.StripModifiers(m.Parameters[0].Type))) { result = m; break; }
         }
         if(this.implicitCoercionFromTable == null)
             this.implicitCoercionFromTable = new TrivialHashtable();
         if(result == null)
             this.implicitCoercionFromTable[sourceType.UniqueKey] = TypeNode.MethodDoesNotExist;
         else
             this.implicitCoercionFromTable[sourceType.UniqueKey] = result;
         return result;
     }
 }