views:

135

answers:

1
+1  Q: 

T4 Confusion

I think I understand the basic principals of T4 but I'm having a hard time figuring out how to apply it to my particular situation.

I have an application that display lists of objects of some kind - doesn't matter what. I want to allow the users to select 1 or more of these objects and submit them to any template. The template could generate, for example, an html file describing the objects or a powershell script to manipulate them in some way or whatever.

The thing I cant figure out is how to pass the selected objects into my custom host.

I could create an extensive tt include file that called my own api to retrieve these objects from their storage, but this seems silly when I already have instances of the objects in scope and I just want to examine them to produce some text output.

I hope this makes sense...

I have tried adding properties to my host and then using the hostspecific setting I thought I could use the objects via these properties but all I get is errors about serialization and such stuff.

A really good example of how to do this would be fantastic :)

Thanks

+1  A: 

Perhaps this article will answer your question. "Standalone Template" may be the best design option. Other options are environment variables and external files. However, I hope you decide against using a custom host (unless you want to have your own, unique flavor of T4, likely incompatible with any other T4 host out there) and use TextTransform.exe instead.

Oleg Sych
I thought I had read all of your bible but I missed that one. The beer is in the mail. Cheers!
Jonesie
It works! Yee ha!My Host uses CallContext to set the logical data then in the template I have:<#@ template language="C#" #><#@ output extension=".ps1" #><#@ import namespace="System.Runtime.Remoting.Messaging" #><#= Service.Url #><#+ Service Service { get { return CallContext.LogicalGetData("Service") as Service; } } #>My custom host adds the relevant imports for Service and other stuff.
Jonesie