R
R
Roman Koff2020-06-08 16:46:00
C++ / C#
Roman Koff, 2020-06-08 16:46:00

How to write a Visual Studio extension for code generation?

How to write a Visual Studio extension so that a list of its methods is formed for a class in its summary.
If the project code is valid, how can the extension get the list of methods of the current edited class?
For example, there is a class:

public class Test : List<string>
{
  public new void Add(string name)
  {
    base.Add(name);
  }
  public new void Remove(string name)
  {
    base.Remove(name);
  }
  public void Write()
  {
    foreach (var item in this)
      Console.WriteLine(item);
  }
}

After executing the extension, the following text should be added before the class name line:
/// <summary>
/// void Add(string name)
/// void Remove(string name)
/// void Write()
/// </summary>
public class Test : List<string>
{

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Tsisar, 2020-06-08
@MaksTR

If the option is suitable, add the partial and summary classes in a separate generated file, then I recommend not to bother with the extension, but use the Text Template Transformation Toolkit (T4) to generate
https://habr.com/ru/post/64895/
https:/ /docs.microsoft.com/en-us/visualstudio/mode...
To get a list of class methods, use reflection
https://metanit.com/sharp/tutorial/14.1.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question