如何在T4模板输出的命名空间? [英] How to output namespace in T4 templates?
本文介绍了如何在T4模板输出的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Visual Studio中设置了TextTemplatingFileGenerator自定义工具类T4模板:
I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio:
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#
var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile);
var namespaceName = "MyNamespace";
#>
namespace <#= namespaceName #>
{
public static class <#= className #>
{
// some generated code
}
}
我怎样才能在Visual Studio中的自定义工具命名空间属性的值,所以我没有硬编码命名空间?
How can I get the value of the "Custom Tool Namespace" property in Visual Studio, so I don't have to hardcode the namespace?
我甚至会很高兴与C#项目的默认命名空间。
I would even be happy with the default namespace for the C# project.
推荐答案
如果你使用Visual Studio 2010中,你可以检索命名空间通过检查CallContext中的NamespaceHint财产
If you're using Visual Studio 2010, you can retrieve the namespace by checking the CallContext's "NamespaceHint" property.
System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint");
这篇关于如何在T4模板输出的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文