我尝试使用msdn中的这个示例来介绍如何为文本模板生成创建自定义主机。
CustomCmdLineHost
类实现ITextTemplatingEngineHost
接口但不完全,ResolveDirectiveProcessor
未实现,并且每次正常发生异常时抛出它。这是ResolveDirectiveProcessor
方法:
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 cannot be found, throw an error.
throw new Exception("Directive Processor not found");
}
传递给此函数的和processorName
是“T4VSHost”,
现在的问题: 在这种方法中返回“T4VSHost”的类型是什么?
P.S。:我试过“Microsoft.Data.Entity.Design.VisualStudio.Directives.FallbackT4VSHostProcessor”,但它似乎并不存在于任何命名空间中。
答案 0 :(得分:0)
似乎唯一的方法是创建该类型。怎么样 ?通过创建一个继承自FallbackT4VSHostProcessor
命名空间的DirectiveProcessor
抽象类的类(让我们称之为Microsoft.VisualStudio.TextTemplating
)(我在互联网上找到的唯一例子是Here )。那么我们需要在FallbackT4VSHostProcessor
中返回ResolveDirectiveProcessor
的类型,如下所示:
Type ITextTemplatingEngineHost.ResolveDirectiveProcessor(string processorName)
{
if (string.Compare(processorName, "T4VSHost", StringComparison.OrdinalIgnoreCase) == 0)
{
return typeof(FallbackT4VSHostProcessor);
}
throw new Exception("Directive Processor not found");
}
我希望有一天能帮到某人。