Export (0) Print
Expand All

RequiresProvidesDirectiveProcessor Class

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

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

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

public abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor

The RequiresProvidesDirectiveProcessor type exposes the following members.

  NameDescription
Protected methodRequiresProvidesDirectiveProcessorWhen overridden in a derived class, initializes a new instance of the RequiresProvidesDirectiveProcessor class.
Top

  NameDescription
Protected propertyErrorsGets the errors that occurred when processing directives. (Inherited from DirectiveProcessor.)
Protected propertyFriendlyNameWhen overridden in a derived class, gets the friendly name of the directive processor.
Protected propertyHostGets the host that is associated with this directive processor.
Top

  NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFinishProcessingRunFinishes a round of directive processing. (Overrides DirectiveProcessor.FinishProcessingRun().)
Protected methodGeneratePostInitializationCodeWhen 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 methodGeneratePreInitializationCodeWhen 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 methodGenerateTransformCodeWhen overridden in a derived class, adds code to the generated transformation class.
Public methodGetClassCodeForProcessingRunGets code to add to the generated transformation class. (Overrides DirectiveProcessor.GetClassCodeForProcessingRun().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetImportsForProcessingRunGets namespaces to import into the generated transformation class. (Overrides DirectiveProcessor.GetImportsForProcessingRun().)
Public methodGetPostInitializationCodeForProcessingRunGets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run. (Overrides DirectiveProcessor.GetPostInitializationCodeForProcessingRun().)
Public methodGetPreInitializationCodeForProcessingRunGets code to initialize when the generated transformation class is initialized, as a consequence of the most recent processing run. (Overrides DirectiveProcessor.GetPreInitializationCodeForProcessingRun().)
Public methodGetReferencesForProcessingRunGets references to pass to the compiler of the generated transformation class. (Overrides DirectiveProcessor.GetReferencesForProcessingRun().)
Public methodGetTemplateClassCustomAttributesGet any custom attributes to put on the template class. (Inherited from DirectiveProcessor.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeInitializes an instance of the directive processor. (Overrides DirectiveProcessor.Initialize(ITextTemplatingEngineHost).)
Protected methodInitializeProvidesDictionaryWhen overridden in a derived class, specifies the provides parameters for each directive.
Protected methodInitializeRequiresDictionaryWhen overridden in a derived class, specifies the requires parameters for each directive.
Public methodIsDirectiveSupportedWhen overridden in a derived class, determines whether the directive processor supports the specified directive. (Inherited from DirectiveProcessor.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodPostProcessArgumentsWhen overridden in a derived class, allows derived classes to make any modifications to the parameters that they provide and require.
Public methodProcessDirectiveProcesses a single directive from a text template file. (Overrides DirectiveProcessor.ProcessDirective(String, IDictionary<String, String>).)
Protected methodProvideUniqueIdProvides an ID that identifies a call to the directive processor.
Public methodStartProcessingRunStarts a directive processor. (Overrides DirectiveProcessor.StartProcessingRun(CodeDomProvider, String, CompilerErrorCollection).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.
Show:
© 2014 Microsoft