在文本中格式化 C# 代码,如 Visual Studio [英] Formatting C# code in text, like Visual Studio

查看:42
本文介绍了在文本中格式化 C# 代码,如 Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你注意到我现在正在编写的这个编辑器,当你按下 Ctrl + K 然后粘贴你的代码并保存它时,它会变成像在 Visual Studio 中一样格式化.

If you notice in this very editor that I am writing in right now, when you press Ctrl + K and then paste your code and save it, it will become formatted like it was in Visual Studio.

现在我想使用 Windows 窗体执行我自己的程序,我想查看我保存的代码片段并相应地对其进行格式化.

Now I want to do my own program using Windows Forms and I would like to view the snippets of codes I save and format it accordingly.

推荐答案

对于我的博客,我使用 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.

这篇关于在文本中格式化 C# 代码,如 Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆