Пример #1
0
        public Class TraverseClass(ClassDeclarationSyntax cds)
        {
            Class retClass = new Class();
            //public List<Delegate> Delegates { get; set; }
            //public List<Method> FunctionDefs { get; set; }
            //public Inheritance Inheritance { get; set; }
            //public List<Module> Modules { get; set; }
            //public List<Preprocessor> Preprocessors { get; set; }
            //public List<Property> Properties { get; set; }
            //public List<Union> Unions { get; set; }
            retClass.Name = cds.Identifier.ValueText;
            if (cds.HasLeadingTrivia)
            {
                SetOuterComments(retClass, cds.GetLeadingTrivia().ToFullString());
            }

            if (cds.HasTrailingTrivia)
            {
                SetInnerComments(retClass, cds.GetTrailingTrivia().ToFullString());
            }
            foreach (SyntaxToken st in cds.Modifiers)
            {
                string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText);
                Encapsulation encap;
                Qualifiers qual;
                if (System.Enum.TryParse<Encapsulation>( modifier, out encap))
                {
                    retClass.Encapsulation.Add(encap);
                }
                else if (System.Enum.TryParse<Qualifiers>(modifier, out qual))
                {
                    retClass.Qualifiers.Add(qual);
                }
            }

            var enums = from aEnu in cds.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnu;
            foreach (EnumDeclarationSyntax eds in enums)
            {
                retClass.Enums.Add(TraverseEnums(eds));
            }

            var structs = from aStruct in cds.ChildNodes().OfType<StructDeclarationSyntax>() select aStruct;
            foreach (StructDeclarationSyntax sds in structs)
            {
                retClass.Structs.Add(TransverseStructs(sds));
            }

            var methods = from aMethod in cds.ChildNodes().OfType<MethodDeclarationSyntax>() select aMethod;
            foreach (MethodDeclarationSyntax mds in methods)
            {
                retClass.Methods.Add(TransverseMethods(mds));
            }

            var Fields = from aField in cds.ChildNodes().OfType<FieldDeclarationSyntax>() select aField;
            foreach (FieldDeclarationSyntax fds in Fields)
            {
                retClass.Fields.Add(TransverseVariables(fds));
            }

            //var properties = from aProperty in cds.ChildNodes().OfType<PropertyDeclarationSyntax>() select aProperty;
            //foreach (PropertyDeclarationSyntax pds in properties)
            //{
            //    //traverse attributes
            //}

            var constructors = from aConstructor in cds.ChildNodes().OfType<ConstructorDeclarationSyntax>() select aConstructor;
            foreach (ConstructorDeclarationSyntax cods in constructors)
            {
                retClass.Constructors.Add(TransverseConstructors(cods));
            }

            var destructors = from aDestructor in cds.ChildNodes().OfType<DestructorDeclarationSyntax>() select aDestructor;
            foreach (DestructorDeclarationSyntax dds in destructors)
            {
                retClass.Destructors.Add(TransverseDestructors(dds));
            }

            var classes = from aClass in cds.ChildNodes().OfType<ClassDeclarationSyntax>() select aClass;
            foreach (ClassDeclarationSyntax cds2 in classes)
            {
                retClass.Classes.Add(TraverseClass(cds2));
            }

            return retClass;
        }