Interface ITemplateContext
- Namespace
- HoofMark.CSharpTemplating.Abstractions
- Assembly
- HoofMark.CSharpTemplating.Abstractions.dll
The context passed to a template's Run method. Provides access to configuration and the ability to write output files.
public interface ITemplateContext
Properties
Config
Configuration values loaded from the sibling .json file (e.g. MyTemplate.json). If no config file exists, this is an empty/no-op implementation — all TryGet calls return false and Get calls return null or default.
ITemplateConfig Config { get; }
Property Value
Methods
ReadFile(string)
Reads a file and returns its content as a string.
string ReadFile(string path)
Parameters
pathstringPath to the file to read. If relative, it is resolved against the following locations in order, using the first match found:
- The directory containing the template file
- The project root (from
cstemplate.config.json, if configured) - The output root directory
If absolute, the path is used directly.
Returns
- string
The full text content of the file.
Exceptions
- FileNotFoundException
Thrown if the file cannot be found at any of the resolved locations.
WriteFile(string, Action<IOutputWriter>)
Write a file by building its content with an IOutputWriter. Useful for code generation where indentation tracking is helpful.
void WriteFile(string relativePath, Action<IOutputWriter> write)
Parameters
relativePathstringRelative path of the file to write.
writeAction<IOutputWriter>An action that receives an IOutputWriter and writes content to it.
WriteFile(string, string)
Write a file with the given content to the output root. The path is relative to the configured output root directory. Intermediate directories are created automatically.
void WriteFile(string relativePath, string content)