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