Open sandboxFocus

Method FromType

FromType<T>()

Creates a TemplateProvider from a type that implements ITemplateProvider.

Declaration
public static TemplateProvider FromType<T>() where T : ITemplateProvider
Returns
Type Description
TemplateProvider

A TemplateProvider that references the specified type.

Type Parameters
Name Description
T

A type that implements ITemplateProvider and contains template methods (methods annotated with TemplateAttribute). The type must not be static; if you need a helper class with only static templates, make the class non-static and add a private constructor to prevent instantiation.

Remarks

Use this method when you want to invoke templates from a class that is not the current aspect or fabric. The type T must implement ITemplateProvider (which is an empty marker interface) and contain one or more template methods.

Important: The type T is never instantiated. This means:

<ul><li>No constructor is required on <code class="typeparamref">T</code></li><li>Instance members of <code class="typeparamref">T</code> are not accessible from the template</li><li>Templates in <code class="typeparamref">T</code> must be <code>static</code> methods</li></ul></p>

If you need to invoke instance templates or access instance state, use FromInstance(ITemplateProvider?) instead, passing an actual instance of the template provider.

See Also