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:

  • No constructor is required on T
  • Instance members of T are not accessible from the template
  • Templates in T must be static methods

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