Is there a way to access the Visual Studio CodeSnippet framework for programmatically processing software fragments?

I am working on a project that will be heavily obscured by the template, but the generated templates may also work well in future projects such as CodeSnippets for Visual Studio.

So, I was wondering, is there a way to access Visual Studio's boot system, parse and display CodeSnippets in any way, form or form?

For example, it would be really easy to do something like this:

var snippet = LoadSnippet("~/path/to/code.snippet"); if (snippet != null) { snippet.TryReplace("$token$", "Some Value"); // and then do something with snippet.ToString(), or... Console.WriteLine(snippet.GetCSharpString()); } 

I know that I can just download .snippet files in XML format and manipulate them manually, but from the point of view of using other things, such as filling in the token defaults, executing functions to replace tokens, or controlling editable from tokens in the fragment file, which is more work than I want to duplicate if I do not need.

Ideas?

Thanks!

+4
source share
1 answer

You should consider a โ€œrealโ€ template tool, such as CodeSmith, or the new Visual Studio 2010 feature. These templates support code-per-runtime. Not sure about the Visual Studio toolkit, but CodeSmith can be launched through the API.

Fragments are much simpler. Do not try to make them what they are not. If you want to use snippets, there are some tools for free download (Snippet Editor, http://www.codeplex.com/SnippetEditor ) to better design them, take advantage of the features, etc., so you are not in raw XML .

+2
source

Source: https://habr.com/ru/post/1301985/


All Articles