public static IReturnType ReadReturnType(BinaryReader reader, INameDecoder nameTable)
        {
            if (ReadNull(reader))
            {
                return(null);
            }
            byte index = reader.ReadByte();

            if (index < 0xFF)
            {
                return(DomReturnType.GetSharedReturnType(index));
            }

            string ns = ReadString(reader, nameTable);
            List <IReturnTypePart> parts = new List <IReturnTypePart> ();

            uint partCount = ReadUInt(reader, 500);

            while (partCount-- > 0)
            {
                ReturnTypePart part = new ReturnTypePart();
                parts.Add(part);
                part.Name        = ReadString(reader, nameTable);
                part.IsGenerated = reader.ReadBoolean();
                uint arguments = ReadUInt(reader, 1000);
                while (arguments-- > 0)
                {
                    part.AddTypeParameter(ReadReturnType(reader, nameTable));
                }
            }

            DomReturnType result = new DomReturnType(ns, parts);

            result.PointerNestingLevel = reader.ReadInt32();
            result.IsNullable          = reader.ReadBoolean();
            result.IsByRef             = reader.ReadBoolean();

            int arrayDimensions = reader.ReadInt32();

            int[] dims = new int [arrayDimensions];
            for (int n = 0; n < arrayDimensions; n++)
            {
                dims [n] = reader.ReadInt32();
            }

            result.SetDimensions(dims);
            return(result);
        }
        public override INode Visit(IReturnType type, IType contextType)
        {
            if (type.GenericArguments.Count == 0 && unit != null)
            {
                foreach (IUsing u in unit.Usings)
                {
                    if (u.IsFromNamespace || u.Aliases.Count == 0 && contextType != null && u.Region.Contains(contextType.Location))
                    {
                        continue;
                    }
                    foreach (KeyValuePair <string, IReturnType> alias in u.Aliases)
                    {
                        if (alias.Key == type.FullName)
                        {
                            return(Visit(alias.Value, contextType));
                        }
                    }
                }
            }

            if (currentMethod != null)
            {
                IMethod method = null;
                if (currentMethod.IsOverride)
                {
                    foreach (IType curType2 in db.GetInheritanceTree(contextType))
                    {
                        foreach (IMethod curMethod in curType2.SearchMember(currentMethod.Name, true))
                        {
                            if (!curMethod.IsOverride && curMethod.Parameters.Count == currentMethod.Parameters.Count && curMethod.TypeParameters.Count == currentMethod.TypeParameters.Count)
                            {
                                method = curMethod;
                                break;
                            }
                        }
                        if (method != null)
                        {
                            break;
                        }
                    }
                }
                if (method == null)
                {
                    method = currentMethod;
                }
                int idx = currentMethod.GetTypeParameterIndex(type.Name);
                if (idx >= 0)
                {
                    ITypeParameter t = method.TypeParameters [idx];
                    DomReturnType  typeParameterReturnType = new DomReturnType(type.FullName);
                    DomType        constructedType         = new InstantiatedParameterType(db, method, t);

                    if (constructedType.BaseType == null)
                    {
                        constructedType.BaseType = DomReturnType.Object;
                    }

                    constructedType.SourceProjectDom = db;

                    typeParameterReturnType.Type                = constructedType;
                    typeParameterReturnType.ArrayDimensions     = type.ArrayDimensions;
                    typeParameterReturnType.PointerNestingLevel = type.PointerNestingLevel;
                    for (int i = 0; i < type.ArrayDimensions; i++)
                    {
                        typeParameterReturnType.SetDimension(i, type.GetDimension(i));
                    }
                    return(typeParameterReturnType);
                }
            }

            IType lookupType = db.SearchType(unit, contextType, resolvePosition, type);

            if (visitAttribute && lookupType == null && type.Parts.Count > 0)
            {
                string oldName = type.Parts [type.Parts.Count - 1].Name;
                type.Parts [type.Parts.Count - 1].Name += "Attribute";
                lookupType = db.SearchType(unit, contextType, resolvePosition, type);
                if (lookupType == null)
                {
                    type.Parts [type.Parts.Count - 1].Name = oldName;
                }
            }

            if (lookupType == null)
            {
                unresolvedCount++;
                return(type);
            }

            List <IReturnTypePart> parts = new List <IReturnTypePart> (type.Parts.Count);
            IType curType  = lookupType.DeclaringType;
            int   typePart = 0;

            while (curType != null)
            {
                ReturnTypePart newPart = new ReturnTypePart {
                    Name = curType.Name
                };
                newPart.IsGenerated = true;
                for (int n = curType.TypeParameters.Count - 1; n >= 0; n--)
                {
                    newPart.AddTypeParameter(new DomReturnType("?"));
                }

                if (typePart >= type.Parts.Count || (type.Parts [typePart].Name != newPart.Name || type.Parts [typePart].GenericArguments.Count != newPart.GenericArguments.Count))
                {
                    parts.Insert(0, newPart);
                    typePart++;
                }
                curType = curType.DeclaringType;
            }

            foreach (ReturnTypePart part in type.Parts)
            {
                ReturnTypePart newPart = new ReturnTypePart();
                newPart.Name = part.Name;
                foreach (IReturnType ga in part.GenericArguments)
                {
                    newPart.AddTypeParameter((IReturnType)ga.AcceptVisitor(this, contextType));
                }
                parts.Add(newPart);
            }

            DomReturnType rt = new DomReturnType(lookupType.Namespace, parts);

            // Make sure the whole type is resolved
            if (parts.Count > 1 && db.SearchType(unit, contextType, resolvePosition, rt) == null)
            {
                unresolvedCount++;
                return(type);
            }

            rt.PointerNestingLevel = type.PointerNestingLevel;
            rt.IsNullable          = type.IsNullable;
            rt.ArrayDimensions     = type.ArrayDimensions;
            for (int n = 0; n < type.ArrayDimensions; n++)
            {
                rt.SetDimension(n, type.GetDimension(n));
            }
            return(db.GetSharedReturnType(rt));
        }
		public static IReturnType ReadReturnType (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
		{
			if (ReadNull (reader))
				return null;
			byte index = reader.ReadByte ();
			if (index < 0xFF) 
				return DomReturnType.GetSharedReturnType (index);
			
			string ns = ReadString (reader, nameTable);
			List<ReturnTypePart> parts = new List<ReturnTypePart> ();
			
			uint partCount = ReadUInt (reader, 500);
			while (partCount-- > 0) {
				ReturnTypePart part = new ReturnTypePart ();
				parts.Add (part);
				part.Name = ReadString (reader, nameTable);
				part.IsGenerated = reader.ReadBoolean ();
				uint arguments  = ReadUInt (reader, 1000);
				while (arguments-- > 0)
					part.AddTypeParameter (ReadReturnType (reader, nameTable, objectTable));
			}
			
			DomReturnType result = new DomReturnType (ns, parts);
			result.PointerNestingLevel = reader.ReadInt32 ();
			result.IsNullable = reader.ReadBoolean ();
			result.IsByRef = reader.ReadBoolean ();
			
			int  arrayDimensions = reader.ReadInt32 ();
			int[] dims = new int [arrayDimensions];
			for (int n=0; n<arrayDimensions; n++)
				dims [n] = reader.ReadInt32 ();
			
			result.SetDimensions (dims);
			return objectTable != null ? (IReturnType) objectTable.GetSharedObject (result) : result;
		}