示例#1
0
        private static bool IsTaskCore(TypeNode type)
        {
            Contract.Assert(_task != null);
            Contract.Assert(_taskGeneric != null);

            if (type.Name.UniqueIdKey == _task.Name.UniqueIdKey)
            {
                return(true);
            }

            if (!type.IsGeneric)
            {
                return(false);
            }

            TypeNode targetType = _taskGeneric.GetGenericTemplateInstance(_taskGeneric.DeclaringModule, type.ConsolidatedTemplateArguments);

            return(targetType.Name.UniqueIdKey == type.Name.UniqueIdKey);
        }
示例#2
0
 private TypeNode/*!*/ ParseArrayOrGenericType(string typeName, TypeNode/*!*/ rootType)
 {
     if (typeName == null || rootType == null) { Debug.Assert(false); return rootType; }
     //Get here after "rootType[" has been parsed. What follows is either an array type specifier or some generic type arguments.
     if (typeName.Length == 0)
         throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName); //Something ought to follow the [
     if (typeName[0] == ']')
     { //Single dimensional array with zero lower bound
         if (typeName.Length == 1) return rootType.GetArrayType(1);
         if (typeName[1] == '[' && typeName.Length > 2)
             return this.ParseArrayOrGenericType(typeName.Substring(2), rootType.GetArrayType(1));
         throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
     }
     if (typeName[0] == '*')
     { //Single dimensional array with unknown lower bound
         if (typeName.Length > 1 && typeName[1] == ']')
         {
             if (typeName.Length == 2) return rootType.GetArrayType(1, true);
             if (typeName[2] == '[' && typeName.Length > 3)
                 return this.ParseArrayOrGenericType(typeName.Substring(3), rootType.GetArrayType(1, true));
         }
         throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
     }
     if (typeName[0] == ',')
     { //Muti dimensional array
         int rank = 1;
         while (rank < typeName.Length && typeName[rank] == ',') rank++;
         if (rank < typeName.Length && typeName[rank] == ']')
         {
             if (typeName.Length == rank + 1) return rootType.GetArrayType(rank + 1);
             if (typeName[rank + 1] == '[' && typeName.Length > rank + 2)
                 return this.ParseArrayOrGenericType(typeName.Substring(rank + 2), rootType.GetArrayType(rank));
         }
         throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
     }
     //Generic type instance
     int offset = 0;
     if (typeName[0] == '[') offset = 1; //Assembly qualified type name forming part of a generic parameter list        
     TypeNodeList arguments = new TypeNodeList();
     int commaPos = FindFirstCommaOutsideBrackets(typeName);
     while (commaPos > 1)
     {
         arguments.Add(this.GetTypeFromSerializedName(typeName.Substring(offset, commaPos - offset)));
         typeName = typeName.Substring(commaPos + 1);
         offset = typeName[0] == '[' ? 1 : 0;
         commaPos = FindFirstCommaOutsideBrackets(typeName);
     }
     //Find the position of the first unbalanced ].
     int lastCharPos = offset;
     for (int leftBracketCount = 0; lastCharPos < typeName.Length; lastCharPos++)
     {
         char ch = typeName[lastCharPos];
         if (ch == '[') leftBracketCount++;
         else if (ch == ']')
         {
             leftBracketCount--;
             if (leftBracketCount < 0) break;
         }
     }
     arguments.Add(this.GetTypeFromSerializedName(typeName.Substring(offset, lastCharPos - offset)));
     TypeNode retVal = rootType.GetGenericTemplateInstance(this.module, arguments);
     if (lastCharPos + 1 < typeName.Length && typeName[lastCharPos + 1] == ']')
         lastCharPos++;
     if (lastCharPos + 1 < typeName.Length)
     {
         //The generic type is complete, but there is yet more to the type
         char ch = typeName[lastCharPos + 1];
         if (ch == '+') retVal = this.GetTypeFromSerializedName(typeName.Substring(lastCharPos + 2), retVal);
         if (ch == '&') retVal = retVal.GetReferenceType();
         if (ch == '*') retVal = retVal.GetPointerType();
         if (ch == '[') retVal = this.ParseArrayOrGenericType(typeName.Substring(lastCharPos + 2, typeName.Length - 1 - lastCharPos - 1), retVal);
     }
     return retVal;
 }