ITextTemplatingEngineHost.ResolveDirectiveProcessor 方法

在已知指令处理器的友好名称时,返回其类型。

命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0(在 Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll 中)

语法

声明
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

参数

  • processorName
    类型:System.String
    要解析的指令处理器的名称。

返回值

类型:System.Type
指令处理器的 Type

备注

该引擎根据用户在文本模板中指定的指令调用此方法。 对于每个文本模板转换,可以调用此方法 0 次、1 次或多次。 有关更多信息,请参见 T4 文本模板指令

如果无法解析指令处理器名称,此方法应该引发异常。

如果主机用来在方法 ResolveDirectiveProcessor 中查找指令处理器的机制不安全,则可能运行恶意指令处理器。 恶意的指令处理器可能提供在运行模板时在完全信任模式下运行的代码。 如果创建自定义主机,则必须使用安全机制(如注册表)来定位指令处理器。 有关更多信息,请参见 文本模板的安全性

示例

下面的代码示例演示了自定义主机的可能实现。 此代码示例摘自为 ITextTemplatingEngineHost 接口提供的一个更大的示例。

有关说明如何为生成的指令处理器解析请求的更详细示例,请参见演练:将主机连接至生成的指令处理器

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 安全性

请参见

参考

ITextTemplatingEngineHost 接口

Microsoft.VisualStudio.TextTemplating 命名空间

ResolveAssemblyReference

ResolveFileName

其他资源

演练:创建自定义文本模板宿主

文本模板的安全性