.NET Code Review
Learn how to create a Quick Command in StackSpot AI to perform .NET code analysis, identify refactoring opportunities, and verify if the code follows best practices for taxonomy and security.
Steps to create a Quick Command
Step 1. Access the StackSpot AI Portal
- Access the StackSpot AI Portal;
- Log in with your account;
Step 2. Create a new Agent
- In the main menu, click on ‘Contents > Quick Command’;
- Click the ‘Create Quick Command: IDE’ button;
- Fill in the information: Quick Command Name, Execution Command, and Description. Example: dotnet-review.
Step 3. Configure the refactoring analysis prompt
- Click on ‘Start’ and select the Prompt option.
- Fill in the fields:
- Prompt Name: analyze-refactoring
- Prompt:
Role: Software engineer specialized in C#
Task: Analyze the selected code and identify refactoring opportunities.
Source code: {{selected_code}}
Expected output: A list of refactoring suggestions, including the justification for each one.
Notes: The suggestions should follow .NET development best practices, such as SOLID.
Step 4: Add best practices analysis prompt
- Click on ‘Add Prompt’ and fill in the fields:
- Prompt Name: analyze-best-practices
- Prompt:
Role: Software engineer specialized in C#
Task: Analyze the selected code and verify if it follows best practices for taxonomy and security.
Source code: {{selected_code}}
Expected output: A detailed report on the best practices followed and those that need improvement, focusing on taxonomy and security.
Notes: The report should include recommendations to improve code security and organization.
Step 5: Finalize the Quick Command
- Click on ‘Finish’ to complete the creation of the Quick Command.
- In the Quick Command Utilization section, choose the Interface option so the command can be executed via the extension's chat.
Step 6: Configure the Final Output
In the Quick Command Utilization screen, insert the following code to display the responses from both prompts:
# analyze-refactoring
`{{analyze-refactoring.answer}}`
# analyze-best-practices
`{{analyze-best-practices.answer}}`
Step 7: Test the Quick Command
- Access your IDE with the StackSpot AI extension installed.
- Select the .NET code you want to review, for example:
public class OrderService
{
public void ProcessOrder(Order order)
{
if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (order.Items.Count == 0)
{
throw new InvalidOperationException("Order must have at least one item.");
}
// Process the order
foreach (var item in order.Items)
{
// Process each item
}
}
}
- Right-click on the selected code and choose ‘StackSpot AI > My Quick Commands > dotnet-review‘.
Step 8: Review the Result
- The Quick Command will analyze the code, identify refactoring opportunities, and verify whether it follows best practices for taxonomy and security.
- The chat will display the result, including refactoring suggestions and the best practices report.