Share via


RequiresProvidesDirectiveProcessor Class

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

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.TextTemplating.DirectiveProcessor
    Microsoft.VisualStudio.TextTemplating.RequiresProvidesDirectiveProcessor

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

Syntax

'Declaration
Public MustInherit Class RequiresProvidesDirectiveProcessor _
    Inherits DirectiveProcessor
public abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor
public ref class RequiresProvidesDirectiveProcessor abstract : public DirectiveProcessor
[<AbstractClass>]
type RequiresProvidesDirectiveProcessor =  
    class 
        inherit DirectiveProcessor 
    end
public abstract class RequiresProvidesDirectiveProcessor extends DirectiveProcessor

The RequiresProvidesDirectiveProcessor type exposes the following members.

Constructors

  Name Description
Protected method RequiresProvidesDirectiveProcessor When overridden in a derived class, initializes a new instance of the RequiresProvidesDirectiveProcessor class.

Top

Properties

  Name Description
Protected property Errors Gets the errors that occurred when processing directives. (Inherited from DirectiveProcessor.)
Protected property FriendlyName When overridden in a derived class, gets the friendly name of the directive processor.
Protected property Host Gets the host that is associated with this directive processor.

Top

Methods

  Name Description
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method FinishProcessingRun Finishes a round of directive processing. (Overrides DirectiveProcessor.FinishProcessingRun().)
Protected method GeneratePostInitializationCode 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.
Protected method GeneratePreInitializationCode 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.
Protected method GenerateTransformCode When overridden in a derived class, adds code to the generated transformation class.
Public method GetClassCodeForProcessingRun Gets code to add to the generated transformation class. (Overrides DirectiveProcessor.GetClassCodeForProcessingRun().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetImportsForProcessingRun Gets namespaces to import into the generated transformation class. (Overrides DirectiveProcessor.GetImportsForProcessingRun().)
Public method GetPostInitializationCodeForProcessingRun Gets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run. (Overrides DirectiveProcessor.GetPostInitializationCodeForProcessingRun().)
Public method GetPreInitializationCodeForProcessingRun Gets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run. (Overrides DirectiveProcessor.GetPreInitializationCodeForProcessingRun().)
Public method GetReferencesForProcessingRun Gets references to pass to the compiler of the generated transformation class. (Overrides DirectiveProcessor.GetReferencesForProcessingRun().)
Public method GetTemplateClassCustomAttributes Get any custom attributes to put on the template class. (Inherited from DirectiveProcessor.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Initialize Initializes an instance of the directive processor. (Overrides DirectiveProcessor.Initialize(ITextTemplatingEngineHost).)
Protected method InitializeProvidesDictionary When overridden in a derived class, specifies the provides parameters for each directive.
Protected method InitializeRequiresDictionary When overridden in a derived class, specifies the requires parameters for each directive.
Public method IsDirectiveSupported When overridden in a derived class, determines whether the directive processor supports the specified directive. (Inherited from DirectiveProcessor.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method PostProcessArguments When overridden in a derived class, allows derived classes to make any modifications to the parameters that they provide and require.
Public method ProcessDirective Processes a single directive from a text template file. (Overrides DirectiveProcessor.ProcessDirective(String, IDictionary<String, String>).)
Protected method ProvideUniqueId Provides an ID that identifies a call to the directive processor.
Public method StartProcessingRun Starts a directive processor. (Overrides DirectiveProcessor.StartProcessingRun(CodeDomProvider, String, CompilerErrorCollection).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate property IDirectiveProcessor.Errors (Inherited from DirectiveProcessor.)
Explicit interface implemetationPrivate property IDirectiveProcessor.RequiresProcessingRunIsHostSpecific (Inherited from DirectiveProcessor.)
Explicit interface implemetationPrivate method IDirectiveProcessor.SetProcessingRunIsHostSpecific (Inherited from DirectiveProcessor.)

Top

Remarks

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 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:

Examples

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;
}
}
}
}

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

Reference

Microsoft.VisualStudio.TextTemplating Namespace

DirectiveProcessor

Other Resources

Creating Custom T4 Text Template Directive Processors