title
stringlengths
3
46
content
stringlengths
0
1.6k
4:334
break;
4:335
}
4:336
}
4:337
}
4:338
catch
4:339
{
4:340
}
4:341
}
4:342
4:343
The idea of this code is to show you the power of some tools to improve the code you deliver. Let us study each of them in the next section, including how to set them up.
4:344
Understanding and applying tools that can evaluate C# code
4:345
The evolution of code analysis in Visual Studio is continuous. This means that Visual Studio 2022 certainly has more tools for this purpose than Visual Studio 2019, and so on.
4:346
One of the issues that you (as a software architect) need to deal with is the coding style of the team. This certainly results in a better understanding of the code. For instance, if you go to the Visual Studio Menu, then Tools -> Options, and then, in the left-hand menu, Text Editor -> C#, you will find ways to deal with different code style patterns, and a bad coding style is even indicated as an error in the Code Style options, as follows:
4:347
4:348
Figure 4.11: Code Style options
4:349
The preceding screenshot chnage that Avoid unused parameters was considered an error.
4:350
After this change, the result of the compilation of the code presented at the beginning of the chapter is different, as you can see in the following screenshot:
4:351
4:352
Figure 4.12: Code Style result
4:353
You can export your coding style configuration and attach it to your project so that it will follow the rules you have defined.
4:354
Another good tool that Visual Studio 2022 provides is Analyze and Code Cleanup. With this tool, you can set up some code standards that can clean up your code. For instance, in the following screenshot, it was set to remove unnecessary code:
4:355
4:356
Figure 4.13: Configure Code Cleanup
4:357
The way to run Code Cleanup is by selecting it with the help of a right-click in the Solution Explorer area, over the project where you want to run it. After that, this process will run in all the code files you have:
4:358
4:359
Figure 4.14: Run Code Cleanup
4:360
After solving the errors indicated by the Code Style and Code Cleanup tools, the sample code we are working on has some minimal simplifications, as follows:
4:361
using System;