madhavrao… » T4 - Host

T4 - Host

Host in T4 is responsible for anything that relates to external environment, including the following:

  1. Providing a file or an assembly if the engine or a directive processor requests one.
  2. The host can search directories and the global assembly cache to locate files and assemblies. (This is implemented in “ResolveAssemblyReference” method of host class)
  3. The host can locate custom directive processor code for the engine. (This is implemented in “ResolveDirectiveProcessor” method of host class)
  4. The host can open and read files and return their contents as strings. (This is implemented in “LoadIncludeText” method of host class. If it returns true then included text in “content” parameter and location of the file in “location” paramter)
  5. Providing lists of standard assemblies and namespaces to the engine. (This is implemented in host class as “StandardAssemblyReferences” and “StandardImports” properties)
  6. The engine uses these assemblies and namespaces when it creates the generated transformation class as part of the text template transformation process.
  7. Providing the application domain that the engine uses to compile and execute the generated transformation class. (This is implemented in “ProvideTemplatingAppDomain” method of host class)
  8. Writing the generated text output file. (Host provides file-encoding and file content to the calling code, actual writing is done my class which holds engine, and host instance)
  9. Setting the default extension for the generated text output files. (Default extension can be changed in host object at runtime by calling “SetFileExtension” method. In case extension is specified in template file using “output” directive it will override everything else.)
  10. Receiving the text template transformation errors from the engine and deciding what to do with them. For example, the host can display the errors in the user interface or write them to a file. (This is implemented in “LogErrors” method of host class. Engine calls this method to pass compile errors to host)
  11. Helping a directive processor resolve a required parameter value if a user has called a directive without providing a value. (This is implemented in “ResolveParameterValue” method of host class)
  12. The directive processor can specify the name of the directive and the parameter and ask the host to provide a default value if it has one.

If you want to use the text template transformation functionality in a custom application, you can write a custom text template host. To create a custom host, you create a class that inherits from ITextTemplatingEngineHost

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>