Example #1
0
 private static void BuildAncestorLookupForClassImpl(string className, ParserContext parserContext, HashSet <string> lookup)
 {
     lookup.Add(className);
     if (FRAMEWORK_CLASSES_AND_PARENTS.ContainsKey(className))
     {
         foreach (string parent in FRAMEWORK_CLASSES_AND_PARENTS[className])
         {
             BuildAncestorLookupForClassImpl(parent, parserContext, lookup);
         }
     }
     else
     {
         TopLevelEntity tle = parserContext.DoLookup(className);
         if (tle is ClassLikeDefinition)
         {
             ClassLikeDefinition cd = (ClassLikeDefinition)tle;
             foreach (ResolvedType parentType in cd.ParentClasses)
             {
                 if (parentType.CustomType != null)
                 {
                     BuildAncestorLookupForClassImpl(parentType.CustomType.FullyQualifiedName, parserContext, lookup);
                 }
                 else if (parentType.FrameworkClass != null)
                 {
                     BuildAncestorLookupForClassImpl(parentType.FrameworkClass, parserContext, lookup);
                 }
                 else
                 {
                     throw new System.NotImplementedException();
                 }
             }
         }
         else
         {
             throw new System.NotImplementedException();
         }
     }
 }
Example #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);
        }