Class RazorEngine<TBaseTemplateType>

Razor Hosting Engine that allows execution of Razor templates outside of ASP.NET. You can execute templates from string or a textreader and output to string or a text reader.

This implementation only supports C#.

System.Object
  System.MarshalByRefObject
    Westwind.RazorHosting.RazorEngine<TBaseTemplateType>
public class RazorEngine<TBaseTemplateType> : MarshalByRefObject

Class Members

MemberDescription

Constructor

Creates an instance of the host and performs basic configuration Optionally pass in any required namespaces and assemblies by name

AddAssembly

Method to add assemblies to the referenced assembly list. Use the DLL name or strongly typed name. Assembly added HAS to be accessible via GAC or in bin/privatebin path

public void AddAssembly(string assemblyPath,     String[] additionalAssemblies)

AddAssemblyFromType

Adds an assembly to the Referenced assemblies based on a type reference. Useful to add the 'host' assembly and model types.

public void AddAssemblyFromType(Type type)

public void AddAssemblyFromType(object instance)

AddNamespace

Method to add namespaces to the compiled code. Add namespaces to minimize explicit namespace requirements in your Razor template code.

Make sure that any required assemblies are loaded first.

public void AddNamespace(string ns,     String[] additionalNamespaces)

public void AddNamespace(String[] additionalNamespaces)

CompileTemplate

Parses and compiles a markup template into an assembly and returns an assembly name. The name is an ID that can be passed to ExecuteTemplateByAssembly which picks up a cached instance of the loaded assembly.

public string CompileTemplate(TextReader templateReader,     string generatedNamespace,     string generatedClassName)

public string CompileTemplate(string templateText,     string generatedNamespace,     string generatedClassName)

GetAssemblyFromId

Allows retrieval of an Assembly cached internally by its id returned from ParseAndCompileTemplate. Useful if you want to write an assembly to disk for later activation

public Assembly GetAssemblyFromId(string assemblyId)

InitializeLifetimeService

Override to allow indefinite lifetime - no unloading

public virtual object InitializeLifetimeService()

RenderTemplate

Execute a template based on a TextReader input into a provided TextWriter object.

public string RenderTemplate(TextReader templateSourceReader,     object model,     TextWriter outputWriter)

public string RenderTemplate(string templateText,     object model,     TextWriter outputWriter,     bool inferModelType)

RenderTemplateFromAssembly

Executes a template based on a previously compiled and cached assembly reference. This effectively allows you to cache an assembly.

public string RenderTemplateFromAssembly(string assemblyId,     object model,     TextWriter outputWriter,     string generatedNamespace,     string generatedClass)

SetError

Sets error information consistently

public void SetError(string message)

public void SetError()

Configuration

Holds Razor Configuration Properties

ErrorMessage

Any errors that occurred during template execution

HostContainer

Provide a reference to a RazorHost container so that it can be passed to a template.

This may be null, but if a container is available this value is set and passed on to the template as HostContainer.

LastException

LastGeneratedCode

Last generated output

LastResultData

Allows retrieval of the template's ResultData property to be retrieved from the last request.

TemplatePerRequestConfigurationData

A property that holds any per request configuration data that is to be passed to the template. This object is passed to InitializeTemplate after the instance was created.

This object must be serializable. This object should be set on every request and cleared out after each request

Requirements

Namespace: Westwind.RazorHosting
Assembly: westwind.razorhosting.dll

© West Wind Technologies, 2018 • Updated: 06/07/18
Comment or report problem with topic