RequiresProvidesDirectiveProcessor Class


The abstract base class for a directive processor that defines and implements a design pattern called requires/provides.

Namespace:   Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating.12.0 (in Microsoft.VisualStudio.TextTemplating.12.0.dll)


public abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor


When overridden in a derived class, initializes a new instance of the RequiresProvidesDirectiveProcessor class.


Gets the errors that occurred when processing directives.(Inherited from DirectiveProcessor.)


When overridden in a derived class, gets the friendly name of the directive processor.


Gets the host that is associated with this directive processor.


(Inherited from Object.)


(Inherited from Object.)


Finishes a round of directive processing.(Overrides DirectiveProcessor.FinishProcessingRun().)

System_CAPS_protmethodGeneratePostInitializationCode(String, StringBuilder, CodeDomProvider, IDictionary<String, String>, IDictionary<String, String>)

When overridden in a derived class, adds code to the initialization code for the generated transformation class. This code is added after the base class is initialized.

System_CAPS_protmethodGeneratePreInitializationCode(String, StringBuilder, CodeDomProvider, IDictionary<String, String>, IDictionary<String, String>)

When overridden in a derived class, adds code to the initialization code of the generated transformation class. This code is added before the base class is initialized.

System_CAPS_protmethodGenerateTransformCode(String, StringBuilder, CodeDomProvider, IDictionary<String, String>, IDictionary<String, String>)

When overridden in a derived class, adds code to the generated transformation class.


Gets code to add to the generated transformation class.(Overrides DirectiveProcessor.GetClassCodeForProcessingRun().)


(Inherited from Object.)


Gets namespaces to import into the generated transformation class.(Overrides DirectiveProcessor.GetImportsForProcessingRun().)


Gets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run.(Overrides DirectiveProcessor.GetPostInitializationCodeForProcessingRun().)


Gets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run. (Overrides DirectiveProcessor.GetPreInitializationCodeForProcessingRun().)


Gets references to pass to the compiler of the generated transformation class.(Overrides DirectiveProcessor.GetReferencesForProcessingRun().)


Get any custom attributes to put on the template class.(Inherited from DirectiveProcessor.)


(Inherited from Object.)


Initializes an instance of the directive processor.(Overrides DirectiveProcessor.Initialize(ITextTemplatingEngineHost).)

System_CAPS_protmethodInitializeProvidesDictionary(String, IDictionary<String, String>)

When overridden in a derived class, specifies the provides parameters for each directive.

System_CAPS_protmethodInitializeRequiresDictionary(String, IDictionary<String, String>)

When overridden in a derived class, specifies the requires parameters for each directive.


When overridden in a derived class, determines whether the directive processor supports the specified directive. (Inherited from DirectiveProcessor.)


(Inherited from Object.)

System_CAPS_protmethodPostProcessArguments(String, IDictionary<String, String>, IDictionary<String, String>)

When overridden in a derived class, allows derived classes to make any modifications to the parameters that they provide and require.

System_CAPS_pubmethodProcessDirective(String, IDictionary<String, String>)

Processes a single directive from a text template file. (Overrides DirectiveProcessor.ProcessDirective(String, IDictionary<String, String>).)

System_CAPS_protmethodProvideUniqueId(String, IDictionary<String, String>, IDictionary<String, String>, IDictionary<String, String>)

Provides an ID that identifies a call to the directive processor.

System_CAPS_pubmethodStartProcessingRun(CodeDomProvider, String, CompilerErrorCollection)

(Inherited from Object.)

To create a custom directive processor, you create a class that inherits from either DirectiveProcessor or RequiresProvidesDirectiveProcessor.

DirectiveProcessor implements the interface that is required to capture parameters from the user, and provides functionality for the generated transformation class. RequiresProvidesDirectiveProcessor RequiresProvidesDirectiveProcessor implements the design pattern, requires/provides, for your directive processor. RequiresProvidesDirectiveProcessor provides additional facilities to capture parameters from the user, and provides functionality to the generated transformation class with specific property names.

For more information, see Creating Custom T4 Text Template Directive Processors.

The transformation engine holds a singleton for any required RequiresProvidesDirectiveProcessor class.

RequiresProvidesDirectiveProcessor implements a state machine.

For example, if a text template has three directive calls to the same directive processor, the engine calls the following methods in order:

The following example demonstrates how to use the RequiresProvidesDirectiveProcessor.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TextTemplating;
using System.Xml;
using System.IO;
using System.Globalization;

namespace Microsoft.Samples.VisualStudio.TextTemplating.DirectiveProcessors
public class DomDirectiveProcessor : RequiresProvidesDirectiveProcessor

// Name of the tag that this directive processor supports.
private const string DomDirectiveTag = "dom";

//Name of the parameter that must be provided for this directive processor to load an XML file
private const string XmlFileRequiredParameterName = "XmlFile";

// Default name of the property that this provider adds to the generated transform class.
private const string DomProvidedParameterName = "Dom";

// Set up the dictionary of items that this directive processor will provide.
protected override void InitializeProvidesDictionary(string directiveName, IDictionary<string, string> providesDictionary)
if (StringComparer.InvariantCultureIgnoreCase.Compare(directiveName, DomDirectiveTag) == 0)
// Populate the dictionary with defualt names.
providesDictionary[DomProvidedParameterName] = DomProvidedParameterName;

// Set up the dictionary of items that this directive processor requires to complete.
protected override void InitializeRequiresDictionary(string directiveName, IDictionary<string, string> requiresDictionary)
if (StringComparer.InvariantCultureIgnoreCase.Compare(directiveName, DomDirectiveTag) == 0)
// Initialize the dictionary with nulls for each required parameter.
requiresDictionary[XmlFileRequiredParameterName] = null;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top