Ejemplo n.º 1
0
        static IType CreateInstantiatedGenericTypeInternal(IType type, IList <IReturnType> genericArguments, GenericTypeInstanceResolver parent)
        {
            // This method is now internal. The public one has been moved to ProjectDom, which take cares of caching
            // instantiated generic types.
            if (type is InstantiatedType)
            {
                return(type);
            }
            string name = GetInstantiatedTypeName(type.Name, genericArguments);
            GenericTypeInstanceResolver resolver = new GenericTypeInstanceResolver();

            resolver.Parent = parent;
            if (genericArguments != null)
            {
                int   j       = genericArguments.Count - 1;
                IType curType = type;
                while (curType != null)
                {
                    string fullTypeName = curType.DecoratedFullName;
                    for (int i = curType.TypeParameters.Count - 1; i >= 0 && j >= 0; i--, j--)
                    {
                        resolver.Add(fullTypeName + "." + curType.TypeParameters [i].Name, genericArguments [j]);
                    }
                    curType = curType.DeclaringType;
                }
            }

            AddInnerTypes(resolver, type.DecoratedFullName, type, genericArguments);

            InstantiatedType result = (InstantiatedType)type.AcceptVisitor(resolver, type);

            if (result.typeParameters != null)
            {
                result.typeParameters.Clear();
            }
            result.Name               = name;
            result.SourceProjectDom   = type.SourceProjectDom;
            result.Resolved           = (type is DomType) ? ((DomType)type).Resolved : false;
            result.GenericParameters  = genericArguments;
            result.UninstantiatedType = type;
            result.DeclaringType      = type.DeclaringType;

            CreateInstantiatedSubtypes(result, type, genericArguments, resolver);
            Dictionary <string, IType> typeTable = new Dictionary <string, IType> ();
            Stack <IType> typeStack = new Stack <IType> ();

            typeStack.Push(result);
            while (typeStack.Count > 0)
            {
                IType cur = typeStack.Pop();
                foreach (var inner in cur.InnerTypes)
                {
                    typeStack.Push(inner);
                }
                var returnType = new DomReturnType(cur);
                typeTable [returnType.ToInvariantString()] = cur;
            }
            result.AcceptVisitor(new SeedVisitor(), typeTable);
            return(result);
        }
Ejemplo n.º 2
0
 static void AddInnerTypes(GenericTypeInstanceResolver resolver, string decoratedFullName, IType type, IList <IReturnType> genericArguments)
 {
     foreach (var inner in type.InnerTypes)
     {
         var constructedReturnType = new DomReturnType(type.Namespace, type.Name, false, genericArguments);
         constructedReturnType.Parts.Add(new ReturnTypePart(inner.Name));
         string constructedName = decoratedFullName + "." + inner.DecoratedFullName;
         resolver.Add(constructedName, constructedReturnType);
         AddInnerTypes(resolver, constructedName, inner, genericArguments);
     }
 }
Ejemplo n.º 3
0
        public static IType CreateInstantiatedGenericTypeInternal(IType type, IList <IReturnType> genericArguments)
        {
            // This method is now internal. The public one has been moved to ProjectDom, which take cares of caching
            // instantiated generic types.
            if (type is InstantiatedType)
            {
                return(type);
            }
            string name = GetInstantiatedTypeName(type.Name, genericArguments);
            GenericTypeInstanceResolver resolver = new GenericTypeInstanceResolver();

            if (genericArguments != null)
            {
                int   j       = genericArguments.Count - 1;
                IType curType = type;
                while (curType != null)
                {
                    string fullTypeName = curType.DecoratedFullName;
                    for (int i = curType.TypeParameters.Count - 1; i >= 0 && j >= 0; i--, j--)
                    {
                        resolver.Add(fullTypeName + "." + curType.TypeParameters[i].Name, genericArguments[j]);
                    }
                    curType = curType.DeclaringType;
                }
            }
            InstantiatedType result = (InstantiatedType)type.AcceptVisitor(resolver, type);

            if (result.typeParameters != null)
            {
                result.typeParameters.Clear();
            }
            result.Name               = name;
            result.SourceProjectDom   = type.SourceProjectDom;
            result.Resolved           = (type is DomType) ? ((DomType)type).Resolved : false;
            result.GenericParameters  = genericArguments;
            result.UninstantiatedType = type;
            result.DeclaringType      = type.DeclaringType;
            CreateInstantiatedSubtypes(result, type, genericArguments);
            return(result);
        }
Ejemplo n.º 4
0
        internal List <IType> ResolveTypeParameters(IEnumerable <IType> types)
        {
            List <IType> result = new List <IType> ();

            foreach (IType type in types)
            {
                if (type.TypeParameters.Count == 0)
                {
                    result.Add(type);
                    continue;
                }
                GenericTypeInstanceResolver resolver = new GenericTypeInstanceResolver();
                string typeName = NamespaceEntry.GetDecoratedName(type);
                foreach (TypeParameter par in type.TypeParameters)
                {
                    resolver.Add(par.Name, new DomReturnType(NamespaceEntry.ConcatNamespaces(typeName, par.Name)));
                }
                resolver.Visit(type, type);
                result.Add((IType)type.AcceptVisitor(resolver, type));
            }
            return(result);
        }
Ejemplo n.º 5
0
        static void CreateInstantiatedSubtypes(InstantiatedType result, IType curType, IList <IReturnType> genericArguments, GenericTypeInstanceResolver resolver)
        {
            foreach (IType innerType in curType.InnerTypes)
            {
                List <IReturnType> newArguments             = new List <IReturnType> ();
                List <int>         removeInheritedArguments = new List <int> ();
                for (int i = 0; i < innerType.TypeParameters.Count; i++)
                {
                    ITypeParameter curParameter = innerType.TypeParameters [i];
                    bool           found        = false;
                    for (int j = curType.TypeParameters.Count - 1; j >= 0; j--)
                    {
                        if (curType.TypeParameters [j].Name == curParameter.Name)
                        {
                            removeInheritedArguments.Add(newArguments.Count);
                            newArguments.Add(genericArguments [j]);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        newArguments.Add(new DomReturnType(curParameter.Name));
                    }
                }

                InstantiatedType innerInstantiatedType = (InstantiatedType)CreateInstantiatedGenericTypeInternal(innerType, newArguments, resolver);
                for (int i = 0, j = 0; i < innerInstantiatedType.TypeParameters.Count && j < innerInstantiatedType.TypeParameters.Count; i++, j++)
                {
                    if (curType.TypeParameters [i].Name == innerInstantiatedType.TypeParameters [j].Name)
                    {
                        innerInstantiatedType.typeParameters.RemoveAt(j);
                        j--;
                    }
                }

                result.Add(innerInstantiatedType);
                CreateInstantiatedSubtypes(innerInstantiatedType, innerType, newArguments, resolver);
                foreach (int i in removeInheritedArguments)
                {
                    if (i >= 0 && i < newArguments.Count)
                    {
                        newArguments.RemoveAt(i);
                    }
                }
            }
        }