0

Hi all!

In earlier days it is possible using Code-Dom, I came to know that using T4 is much easier than Code-Dom. I have gone through many articles but still I am not in a situation to draft-out the code which will meet my requirements.

I need to generate a code on the basis of an auto-generated XML document [I am able to generate the XML document as per my requirements].

It seems like this :

    <?xml version="1.0" encoding="utf-8" ?>
<GeneratedSolution Name ="name of Solution">
<GeneratedProject ID="RepoProject" Name ="name of Project" MajorVersion="1" MinorVersion="0" CopyRight="GeneratedProject company" Language="C#" OutExtension="cs">
<Compiler path = "../path/compilername" Build="silent" ExternalBuildTool="NAnt" />

<GeneratedRepository Name ="name of Repository Class" Description="This is generated Repository class would be used for overall-application" TemplateRefence ="../path/repository.tt">
<Operation Name = "Operation1" Description = "This is operation1 of Repository class">
<operationID>1</operationID>
</Operation>
<Operation Name = "Operation2" Description = "This is operation2 of Repository class">
<operationID>2</operationID>
</Operation>
</GeneratedRepository>

</GeneratedProject>

<GeneratedProject ID="BusinessProject" Name ="name of Project" MajorVersion="1" MinorVersion="0" CopyRight="GeneratedProject company">

<GeneratedBusiness Name ="name of Business Class" Description="This is generated Business class would be used for overall-application" TemplateRefence ="../path/business.tt">
<Operation Name = "Operation1" Description = "This is operation1 of Business class">
<operationID>1</operationID>
</Operation>
<Operation Name = "Operation2" Description = "This is operation2 of Business class">
<operationID>2</operationID>
</Operation>
</GeneratedBusiness>

</GeneratedProject>

<GeneratedProject ID="UIProject" Name ="name of Project" MajorVersion="1" MinorVersion="0" CopyRight="GeneratedProject company">

<GeneratedUI Name ="name of UI Class" Description="This is generated UI class would be used for overall-application" TemplateRefence ="../path/UI.tt">
<Operation Name = "Operation1" Description = "This is operation1 of UI class">
<operationID>1</operationID>
</Operation>
<Operation Name = "Operation2" Description = "This is operation2 of UI class">
<operationID>2</operationID>
</Operation>
</GeneratedUI>

</GeneratedProject>

</GeneratedSolution>

No. of classes, projects may vary within single solution. I read some articles which provide an idea to create project from xml but I need something more to generate code as per above sample of 'XML'.

Any help in this regards will be much appreciated.

Gaurav Arora
  • 2,243
  • 6
  • 40
  • 57

2 Answers2

1

Disclaimer - our discovered methodology but completely open source.

On the linked blog we are describing a way to control your generation output based on strongly-defined input data (in XML schema form). We got a mention through T4 Team's Blog - to underline that it is standard T4 use only:

http://blogs.msdn.com/b/t4/archive/2011/11/30/some-nice-new-getting-started-with-t4-videos.aspx

The link to blog's videos can be reached directly through:

http://abstractiondev.wordpress.com/demo-videos/

For T4 seasoned users the videos already start from scratch and explain the usage. I am in process of adding the basic structure through simple download (for git users it's available through git at https://github.com/abstractiondev/absInitializer).

If you need any assistance on that, just drop me a line through the contact info on that blog and I'll "abstract" it for you, if you like our methodology approach and want to use that for your generation.

Kallex
  • 498
  • 2
  • 10
0

You can use Mono.TextTemplating (part of MonoDevelop) to run T4 templates from your own app and generate any part of code you want. If you don't like the idea of separate app, it is possible to write custom code tool for visual studio which will run all transformations you need.

Novakov
  • 3,055
  • 1
  • 16
  • 32