简体   繁体   中英

VS2010 extension for formatting C# code

I want to create a Visual Studio Extension. That extension, whenever ran by the user will primarily format/indent C# code in a defined manner. 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. 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? or any general APIs that can help me in achieving this kind of thing.

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 ). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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