This topic has not yet been rated - Rate this topic

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 abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor
public abstract class RequiresProvidesDirectiveProcessor extends DirectiveProcessor
public abstract class RequiresProvidesDirectiveProcessor extends DirectiveProcessor

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

The difference between these two is that DirectiveProcessor implements the minimum interface necessary to capture parameters from the user, and provide functionality to the generated transformation class. RequiresProvidesDirectiveProcessor defines and implements a design pattern called requires/provides. RequiresProvidesDirectiveProcessor provides richer facilities to capture parameters from the user, and to provide functionality to the generated transformation class, with specific property names. The text template end user can also override the property names.

For more information, see Directive Processors.

The text template transformation engine will hold a singleton instance of any required RequiresProvidesDirectiveProcessor classes.

RequiresProvidesDirectiveProcessor implements a state machine.

For example, if a text template has three directive calls to the same directive processor, the engine will call the following methods in the following 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;
}
}
}
}
System.Object
   Microsoft.VisualStudio.TextTemplating.DirectiveProcessor
    Microsoft.VisualStudio.TextTemplating.RequiresProvidesDirectiveProcessor
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ