Class RazorTemplateBase

Base class used for Razor Page Templates - Razor generates a class from the parsed Razor markup and this class is the base class. Class must implement an Execute() method that is overridden by the parser and contains the code that generates the markup. Write() and WriteLiteral() must be implemented to handle output generation inside of the Execute() generated code.

This class can be subclassed to provide custom functionality. One common feature likely will be to provide Context style properties that are application specific (ie. HelpBuilderContext) and strongly typed and easily accesible in Razor markup code.

System.Object
  System.MarshalByRefObject
    Westwind.RazorHosting.RazorTemplateBase
public class RazorTemplateBase : MarshalByRefObject, IDisposable

Class Members

MemberDescription

Constructor

Dispose

public virtual void Dispose()

Execute

Razor Parser overrides this method, but this method is effectively never called - it's just a placeholder in order to allow invoking the template.

public virtual void Execute()

HtmlEncode

public virtual string HtmlEncode(string input)

public virtual string HtmlEncode(object input)

InitializeLifetimeService

Force this host to stay alive indefinitely

public virtual object InitializeLifetimeService()

InitializeTemplate

This method is called upon instantiation and allows passing custom configuration data to the template from the Engine.

This method can then be overridden

public virtual void InitializeTemplate(object model,     object configurationData)

Raw

public virtual RawString Raw(string text)

public virtual RawString Raw(RawString text)

RenderTemplate

Allows rendering a dynamic template from within the running template. The template passed must be a string and you can pass a model for rendering.

This is useful to support nested templating for allowing rendered values to contain embedded Razor template expressions which is useful where user generated content may contain Razor template logic.

public virtual string RenderTemplate(string template,     object model)

Write

Writes an expression value. This value is HtmlEncoded always

public virtual void Write(object value)

WriteAttribute

WriteAttribute implementation lifted from ANurse's MicroRazor Implementation and the AspWebStack source.

public virtual void WriteAttribute(string name,     PositionTagged prefix,     PositionTagged suffix,     AttributeValue[] values)

WriteAttributeTo

WriteAttributeTo implementation lifted from ANurse's MicroRazor Implementation and the AspWebStack source.

public virtual void WriteAttributeTo(TextWriter writer,     string name,     PositionTagged prefix,     PositionTagged suffix,     AttributeValue[] values)

WriteLiteral

Writes a literal string. Used to write generic text from the page markup (ie. non-expression text)

public virtual void WriteLiteral(object value)

WriteLiteralTo

Writes the provided , as a literal, to the provided .

public virtual void WriteLiteralTo(TextWriter writer,     object value)

WriteTo

public virtual void WriteTo(TextWriter writer,     object value)

Engine

Instance of the RazorEngine object.

HostContainer

Instance of the HostContainer that is hosting this Engine instance. Note that this may be null if no HostContainer is used.

Note this object needs to be cast to the the appropriate Host Container

Html

Simplistic Html Helper implementation

Model

You can pass in a generic context object to use in your template code

Request

Class that provides request specific information. May or may not have its member data set.

Response

Class that generates output. Currently ultra simple with only Response.Write() implementation.

ResultData

An optional result property that can receive a a processing result that can be passed back to the the caller.

TemplateConfigData

Requirements

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

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