Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > How to generate code for a method in an existing class using T4 Template
 

How to generate code for a method in an existing class using T4 Template

Hi,

I have generated a class with a method inside using T4 Template. Now i need to create another method in the same class using T4. How to do that? Can anyone provide me some samples?

Thanks a lot,

Syamala.

Syamala_rsv  Tuesday, April 15, 2008 6:59 AM

Hi Syamala,

T4 won't help in this case. Ifyou have an already existing class and you want to add a method to it, while you can generete the body of the method with a T4 template you will need to write code to actually edit the existing file and properly adding the generated method to that existing class.

What you need to look for is VS's CodeModel, which you can use to get to an existing class, browse its methods, etc. Unfortunately, CodeModel doesn't support adding a method body, but at least, once you get there to the right class using Code Model you can edit the text buffer and add the new method as raw text.

I suggest you ping the Visual Studio Extensibility forum, right here on MSDN, to get more help on how to use CodeModel, etc.

thanks,

-vga.

vga  Tuesday, April 15, 2008 11:49 PM

Hi Syamala,

T4 won't help in this case. Ifyou have an already existing class and you want to add a method to it, while you can generete the body of the method with a T4 template you will need to write code to actually edit the existing file and properly adding the generated method to that existing class.

What you need to look for is VS's CodeModel, which you can use to get to an existing class, browse its methods, etc. Unfortunately, CodeModel doesn't support adding a method body, but at least, once you get there to the right class using Code Model you can edit the text buffer and add the new method as raw text.

I suggest you ping the Visual Studio Extensibility forum, right here on MSDN, to get more help on how to use CodeModel, etc.

thanks,

-vga.

vga  Tuesday, April 15, 2008 11:49 PM

You can use google to search for other answers

Custom Search

More Threads

• Um, does anyone at Microsoft care or support GAT?
• How to get recipe arguments value
• Actions in Visual Studio 2005 Guidance Automation Toolkit (GAT) Very Slow
• Deploying Guidance Package
• ADO.net doesn't work with visual studio 2008
• GAX and templates in VS
• have GetProjectAction vstemplate to execute a recipe
• Build class from database table or view
• Change location solution is unfolded to
• SCSF April 2008 - WPF Resource Dictionary implementation