Share via


ITextTemplatingEngineHost.ResolveDirectiveProcessor Method

Returns the type of a directive processor, given its friendly name.

Namespace:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 (in Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll)

Syntax

'Declaration
Function ResolveDirectiveProcessor ( _
    processorName As String _
) As Type
Type ResolveDirectiveProcessor(
    string processorName
)
Type^ ResolveDirectiveProcessor(
    String^ processorName
)
abstract ResolveDirectiveProcessor : 
        processorName:string -> Type
function ResolveDirectiveProcessor(
    processorName : String
) : Type

Parameters

  • processorName
    Type: String

    The name of the directive processor to be resolved.

Return Value

Type: Type
The Type of the directive processor.

Remarks

The engine calls this method based on the directives the user has specified in the text template. This method can be called 0, 1, or multiple times, for each text template transformation. For more information, see T4 Text Template Directives.

If the directive processor name cannot be resolved, this method should throw an exception.

If the mechanism that the host uses to find a directive processor in the method ResolveDirectiveProcessor is not secure, a malicious directive processor could be run. The malicious directive processor could provide code that is run in full trust mode when the template is run. If you create a custom host, you must use a secure mechanism, such as the registry, to locate directive processors. For more information, see Security of Text Templates.

Examples

The following code example shows a possible implementation for a custom host. This code example is part of a larger example that is provided for the ITextTemplatingEngineHost interface.

For a more detailed example that shows how to resolve a request for a generated directive processor, see Walkthrough: Connecting a Host to a Generated Directive Processor.

public Type ResolveDirectiveProcessor(string processorName)
{
    //this host will not resolve any specific processors

    //check the processor name, and if it is the name of a processor the 
    //host wants to support, return the type of the processor
    //---------------------------------------------------------------------
    if (string.Compare(processorName, "XYZ", StringComparison.OrdinalIgnoreCase) == 0)
    {
        //return typeof();
    }

    //this can be customized to search specific paths for the file,
    //or to search the GAC

    //if the directive processor can not be found, throw an error
    throw new Exception("Directive Processor not found");
}
Public Function ResolveDirectiveProcessor(ByVal processorName As String) As System.Type Implements Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost.ResolveDirectiveProcessor
    'this host will not resolve any specific processors

    'check the processor name, and if it is the name of a processor the 
    'host wants to support, return the type of the processor
    '---------------------------------------------------------------------
    If String.Compare(processorName, "XYZ", StringComparison.OrdinalIgnoreCase) = 0 Then
        'return typeof()
    End If

    'this can be customized to search specific paths for the file,
    'or to search the GAC

    'if the directive processor can not be found, throw an error
    Throw New Exception("Directive Processor not found")
End Function

.NET Framework Security

See Also

Reference

ITextTemplatingEngineHost Interface

Microsoft.VisualStudio.TextTemplating Namespace

ResolveAssemblyReference

ResolveFileName

Other Resources

Walkthrough: Creating a Custom Text Template Host

Security of Text Templates