-
Notifications
You must be signed in to change notification settings - Fork 8
Parsing and Generating code
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. :)
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.
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.
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 is just serialized and deserialized from DTOs. Done by manually building an XDocument.