Create Two Partial Classes From GAX
I currently have a GAX project that creates a class from a database table and puts the new class in a selected folder. What I want to do is the following.
- User selects database table (Done)
- Create Class object (Done)
- Create CRUD sp (Need To Do)
- Create strongly typed dataset (Need To Do)
I have steps 1 and 2 done. I know how to do step 3 also.
The strongly typed dataset will have an xsd and its associated code behind needs to be created. My question is.
To create the class I use an AddItemFromString action.
To create the CRUD sp as part of the same recipe do I just create another AddItemFromString action?
For the strongly typed dataset since partial classes are involved, can I create each file separately using a T4 template with AddItemFromString and VS will join them together? Or do I need to do something special?
Thanks,
Gaurav
[932 byte] By [
Sonu76] at [2008-1-7]
Hi Sonu,
You can add a nested file creating your own AddItemFromString action to add the second item.
Basically you can do the same what is doing the AddItemFromString action which is writing the content to a temporary file and then add the content to the project in the following way:
string tempfile = Path.GetTempFileName(); using (StreamWriter sw = new StreamWriter(tempfile, false)) {
sw.WriteLine(
this.content); }
project.ProjectItems.AddFromTemplate(tempfile,
"foo.cs");
so, you have to change the project for projectItem which also have a collection of ProjectItems which in fact is the nested child collection.
you code should looks like this:
string tempfile = Path.GetTempFileName();
using (StreamWriter sw = new StreamWriter(tempfile, false))
{
sw.WriteLine(this.content);
}
projectItem.ProjectItems.AddFromTemplate(tempfile, "foo.cs");
where "foo.cs" will be the name of the new item.
You can get the projectItem from the first AddItemFromString action using the output argument ProjectItem.
hope it helps.
jose.