Esempio n. 1
0
        internal Type ReadType(string typeName = null, bool ignoreException = false)
        {
            Type type = null;
            StringBuilder sbValue =
                new StringBuilder(string.IsNullOrEmpty(typeName) ? spResult.Next() : typeName);
            do
            {
                // read generic parameters
                if (spResult.PeekNext() == "<")
                {
                    spResult.Skip();
                    List<Type> listGenericType = new List<Type>();
                    while (true)
                    {
                        listGenericType.Add(ReadType());
                        if (spResult.PeekNext() == ",")
                            spResult.Skip();
                        else
                            break;
                    }
                    NextIsEqual(">");

                    sbValue.AppendFormat("`{0}[{1}]", listGenericType.Count,
                        string.Join(",", listGenericType
                            .Select(p => "[" + p.AssemblyQualifiedName + "]").ToArray()));
                }

                type = GetType(sbValue.ToString());
                if (type == null)
                {
                    bool result = NextIsEqual(".", false);
                    if (!result)
                    {
                        if (ignoreException)
                            break;
                        throw new ParseUnfindTypeException(sbValue.ToString(), spResult.Index);
                    }
                    sbValue.Append(".");
                    sbValue.Append(spResult.Next());
                }
            } while (type == null);

            return type;
        }