Ejemplo n.º 1
0
        public static ResolvedType CreatePrimitive(string name, Token throwToken)
        {
            if (PRIMITIVE_TYPES.Contains(name))
            {
                return(new ResolvedType()
                {
                    Generics = EMPTY_GENERICS,
                    IsVoid = name == "void",
                    PrimitiveType = name,
                });
            }

            throw new ParserException(throwToken, "Unrecognized primitive type: " + name);
        }
Ejemplo n.º 2
0
        public static ResolvedType Create(CSharpType type, string[] prefixes, ParserContext context)
        {
            ResolvedType[] generics = EMPTY_GENERICS;
            if (type.Generics.Length > 0)
            {
                generics = type.Generics.Select(g => Create(g, prefixes, context)).ToArray();
            }

            string typeString = type.RootTypeString;

            if (typeString == "[" || typeString == "?")
            {
                return(new ResolvedType()
                {
                    IsArray = typeString == "[",
                    IsNullable = typeString == "?",
                    Generics = generics,
                });
            }

            if (PRIMITIVE_TYPES.Contains(typeString))
            {
                return(new ResolvedType()
                {
                    Generics = EMPTY_GENERICS,
                    PrimitiveType = typeString,
                    IsVoid = typeString == "void",
                });
            }
            foreach (string prefix in prefixes)
            {
                string fullyQualifiedName = prefix + typeString;
                if (FRAMEWORK_CLASSES_AND_PARENTS.ContainsKey(fullyQualifiedName))
                {
                    return(new ResolvedType()
                    {
                        FrameworkClass = fullyQualifiedName,
                        Generics = generics,
                    });
                }

                if (GetFrameworkEnum(fullyQualifiedName) != null)
                {
                    return(new ResolvedType()
                    {
                        FrameworkClass = fullyQualifiedName,
                        Generics = EMPTY_GENERICS,
                        IsEnum = true,
                    });
                }
                if (context != null)
                {
                    TopLevelEntity tle = context.DoLookup(fullyQualifiedName);
                    if (tle != null)
                    {
                        return(new ResolvedType()
                        {
                            CustomType = tle,
                            Generics = generics,
                            IsEnum = tle is EnumDefinition,
                        });
                    }
                }
            }

            return(null);
        }