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 (in Microsoft.VisualStudio.TextTemplating.dll)


Public MustInherit Class RequiresProvidesDirectiveProcessor _
    Inherits DirectiveProcessor
Dim instance As RequiresProvidesDirectiveProcessor
public abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor
public ref class RequiresProvidesDirectiveProcessor abstract : public DirectiveProcessor
public abstract class RequiresProvidesDirectiveProcessor extends DirectiveProcessor


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. RequiresProvidesDirectiveProcessorRequiresProvidesDirectiveProcessor 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 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;

Inheritance Hierarchy


Thread Safety

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

See Also


RequiresProvidesDirectiveProcessor Members

Microsoft.VisualStudio.TextTemplating Namespace


Other Resources

Creating Custom Text Template Directive Processors