Skip to content

Parsing and Generating code

Lars-Erik Aabech edited this page Oct 14, 2013 · 5 revisions

Just a stub to show how the refactoring progress is coming along.

2013-10-14 Next step is to wrap the refactored stuff in a nice API, test the ApplicationEvents handler, then build a new release. :)

Intermediate DTOs

XML and code is parsed into DTOs which serve as an intermediate level between parsing code then serializing XML, and deserializing XML then generating code.

Controlling code generation

Code generation is done by composite CodeGeneratorBase implementations.

The default factory looks like this:

    private CodeGeneratorBase CreateGenerators(ContentTypeConfiguration c, CodeGeneratorBase infoGenerator, IEnumerable<DataTypeDefinition> dataTypes)
    {
        return new NamespaceGenerator(c,
            new ImportsGenerator(c),
            new ClassGenerator(c,
                new EntityDescriptionGenerator(c),
                infoGenerator,
                new StructureGenerator(c),
                new PropertiesGenerator(c,
                    new PropertyDeclarationGenerator(c, dataTypes.ToList(), new EntityDescriptionGenerator(c)),
                    new PropertyBodyGenerator(c)
                    )
                )
            );
    }

This makes it easy to change for instance how and which attributes are generated for the classes.

Controlling parsing (code-first)

Parsing code is done by composite ContentTypeCodeParserBase implementations.

For some amazing reason, it's a lot easier than generating code. :)

    protected List<ContentTypeCodeParserBase> CreateDocumentTypeParser()
    {
        return new List<ContentTypeCodeParserBase>
        {
            new DocumentTypeInfoParser(Configuration),
            new StructureParser(Configuration),
            new PropertiesParser(Configuration,
                new PropertyParser(Configuration, DataTypes)
            ),
            new TabsParser(Configuration)
        };
    }

XML

XML is just serialized and deserialized from DTOs. Done by manually building an XDocument.

Clone this wiki locally