justromagod
justromagod

Reputation: 993

How to generate function call in Visual Studio from known C# function in [CSharp]?

Where are code located for Visual Studio 2017/19 for refactor operations like

Refactor operation in VS2019: https://learn.microsoft.com/en-us/visualstudio/ide/refactoring-in-visual-studio?view=vs-2019

Can I locate code and recompile it for my instance of Visual Studio?

I want to make new command, when Given existing function like

 private void Call(int v1, int v2, string v3, int v4, int v5) {
     throw new NotImplementedException();
 }

I can generate code which calls this function

int v1 = default(int);
int v2 = default(int);
string v3 = default(string);
int v4 = default(int);
int v5 = default(int);

Call(v1: v1, v2: v2, v3: v3, v4: v4, v5: v5);

Upvotes: 0

Views: 734

Answers (1)

w5l
w5l

Reputation: 5746

To write your own functions for generating/modifying code, you want Roslyn syntax transformation:

https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-transformation

In short:

  • Install the .NET Compiler Platform SDK
  • Create a new C# Stand-Alone Code Analysis Tool project. In Visual Studio, right-click the SyntaxTransformationQuickStart solution node. Choose Add > New Project to display the New Project dialog. Under Visual C# > Extensibility, choose Stand-Alone Code Analysis Tool.
  • Create and transform trees

Upvotes: 1

Related Questions