简体   繁体   English

使类或名称空间中的所有字符串为逐字字符串文字

[英]Make all Strings in class or namespace Verbatim String literals

Is it possible in .NET to make all strings within a class, namespace, file, etc. Verbatim String Literals. .NET是否可以在类,名称空间,文件等中创建所有字符串。逐字字符串文字。

There are always a file or two that simply need tons of escaping, where it would be nice to have all strings be considered Verbatim String Literals unless otherwise specified (IE opposite of default .NET behavior). 总会有一个或两个文件需要大量转义,如果没有另外指定,将所有字符串都视为逐字字符串文字将是很好的选择(IE与默认.NET行为相反)。

Use Case: In some of our constant declaration files (that don't belong in the Resource files). 用例:在我们的某些常量声明文件中(不属于资源文件)。 Also in helper files for Razor where we are escaping HTML over and over again. 同样在Razor的帮助文件中,我们一遍又一遍地转义HTML。

Simply read a text file at run-time. 只需在运行时读取文本文件即可。

A compile time .NET file really isn't available to the best of my knowledge. 据我所知,确实无法使用编译时的.NET文件。

There's no built in compiler switch to do this. 没有内置的编译器开关可以执行此操作。 You could probably hack something up with Roslyn depending on which version of VS you're using, but it'd be really confusing for other users I suspect. 根据您使用的VS版本,您可能会用Roslyn破解一些东西,但是对于其他我怀疑的用户来说,这确实令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM