RequiresProvidesDirectiveProcessor Class
Assembly: Microsoft.VisualStudio.TextTemplating (in microsoft.visualstudio.texttemplating.dll)
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:
-
StartProcessingRun
-
ProcessDirective
-
ProcessDirective
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; } } } }
Microsoft.VisualStudio.TextTemplating.DirectiveProcessor
Microsoft.VisualStudio.TextTemplating.RequiresProvidesDirectiveProcessor
Reference
RequiresProvidesDirectiveProcessor MembersMicrosoft.VisualStudio.TextTemplating Namespace
DirectiveProcessor Class