[英]VS2010 extension for formatting C# code
I want to create a Visual Studio Extension. 我想创建一个Visual Studio扩展。 That extension, whenever ran by the user will primarily format/indent C# code in a defined manner.
无论何时由用户运行,该扩展名将主要以定义的方式格式化/缩进C#代码。 For example
例如
private void Method(int a, int b)
{
}
will be converted to something like 将被转换为类似
private void Method
(
int a,
int b
)
{
}
At this point I have no experience or idea about the APIs that I can use for this kind of task. 目前,我对可用于此类任务的API尚无经验或想法。 I would like to know if there are any APIs that MS provides for parsing C# code in a .cs file or any third party APIs?
我想知道MS是否提供任何API来解析.cs文件中的C#代码或任何第三方API? or any general APIs that can help me in achieving this kind of thing.
或任何可以帮助我实现此类目标的常规API。
You could use the CodeElement interface (have a look at this example: HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro or add-in ). 您可以使用CodeElement接口(请看以下示例: HOWTO:从Visual Studio .NET宏或加载项中导航文件的代码元素 )。 With that you will be able to get information about methods, for example, but I do not know if that allows you to go beyond that level.
这样,您就可以获取有关方法的信息,但是我不知道是否可以超出该范围。
If that's not enough for you, Irony comes with a C# grammar in the examples. 如果这还不足以满足您的需求,示例中将提供Irony的C#语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.