且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在文本中格式化 C# 代码,如 Visual Studio

更新时间:2023-01-20 07:51:38

对于我的博客,我使用 Manoli 的 C#格式化程序.

For my blog, I use Manoli's C# formatter.

格式化程序的源代码可用.

基本上,您收集所有关键字、编译器指令...等.并使用正则表达式来查找它们.然后作者将 HTML 标签包裹在它们周围以格式化文本.

Basically you collect all the keywords, compiler directives...etc. and use regular expressions to find them. Then the author wraps HTML tags around them to format the text.

您可以采用相同的方法并包含您自己的格式,该格式与您要使用的任何 Windows 窗体控件兼容.

You could follow the same approach and include your own formatting which is compatible with whichever Windows Forms control you want to use.