在 C# 中动态更改命名空间 [英] Dynamically change namespace in C#
本文介绍了在 C# 中动态更改命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情.如果定义了 DEBUG,则命名空间为 Test,或者命名空间为 TestB.请参阅下面的示例代码.我可以这样做还是您有更好的想法来实现这一目标?提前致谢!
I want to do something like this. If DEBUG is defined then the namespace is Test, or the namespace is TestB. See the sample code bellow. Can I do that or you have better ideas to achieve this? Thanks in advance!
# if DEBUG
[SomekindofAttribute(Namespace = "Test")]
#endif
namespace TestB
{
public class Program
{}
}
推荐答案
您可以这样做:
#if DEBUG
namespace TestB
#else
namespace Test
#endif
{
public class Program { }
}
虽然这看起来是一个非常的坏主意.使用 Program
的所有内容都必须对其 using
声明执行相同的预处理器指令.
Though this looks like a very bad idea. Everything using Program
would have to do the same preprocessor directives for their using
declarations, too.
这篇关于在 C# 中动态更改命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文