[MUSIC].
>> Hi everyone. My name is Mika and today I'm going to talk about
some essential tips and tricks to
help increase your .Net productivity.
Visual Studio provides hints to help you maintain and
modify your code in the form of code fixes and refactorings.
This appear as light bulbs and
screwdrivers next to your code or in the margin.
The hints can resolve warnings and
errors as well as provide suggestions.
For example, here I'm getting
a suggestion to used a C# coding convention,
converting this namespace to a file's scope Namespace.
This will unless a class definition within
a namespace which gets rid of that extra space in the margin.
Here I have a suggested code fix,
helping me resolve this warning
by declaring this type as nullable.
Some code fixes and refactorings can also be
invoked from solution explorer right click on Menu.
Like sync namespaces,
allowing me to synchronize
my namespace to match my folder structure.
We also have removed unuse references allowing you
to clean up project references
and you get packages that have no usage.
Code fixes and refactorings are powered by analyzers.
An analyzer is a .Net compiler platform tool that inspects
your code, reports issues, and suggests fixes for them.
.Net 5 we ships all over .Net
analyzers as part of its on .Net SDK so,
you automatically get guidance on
best practices when writing C# or Visual Basic Code.
You can view these analyzers in an EditorConfig.
EditorConfig is a single file that helps you
maintain consistent code by defining coding conventions.
They can live with your code in
its repository and use the same source control.
This way the coding convention guidance is still the same
for everyone on your team who clones from that repository.
With EditorConfig, you can enable or disable
individual analyzers and configure
the severity to which you want each analyzer enforced.
For example, here I have
an analyzer suggestion letting me
know that this member can be static.
I can go ahead and pump up
the severity of this analyzer to be a warning,
either in my EditorConfig
or within the editor from my light bulb menu,
which will automatically update my EditorConfig.
Notice how in the error list and in the editor,
the violation is now a bit more obvious.
Analyzers also surface and
automatic code fix through the light bulb.
I'm going to go ahead and accept this fix.
You may have heard of source generators,
a technology similar to analyzers that
ship as part of the .Net compiler Platform SDK.
A source generator is a piece of code
that runs during compilation and can inspect
your program to produce
additional source files that are
compiled together with the rest of your
code. .Net 6 we ship some source generators
as part of the .Net SDK to help you write efficient code.
I'll demonstrate one that helps with JSON.
Here I have my astronomer record
that stores information about astronomer.
I want to serialize this object to a JSON string.
Doing this can be pretty tedious and error prone.
Luckily, source generators will generate
all of that code for me instantaneously.
You might be wondering how?
Well, this JSON serializable attribute
tells the source generator to generate
source codes to help serialize this type.
If I click on the Dependencies node and then the Analyzers node,
you can see here I have my systems text face on
source generator and here is
all the code that the source generator creates.
You can see that all of these properties
for my astronomer is also being handled.
Luckily, I don't have to write this myself.
I can just use the JSON serializable attribute
and the source generator will bring all this code for me.
Most importantly, the source generated code is
the most performant way to serialize the type to a JSON string.
What's really cool is I can easily navigate
from my editor to a source generated file
until a sentence and code completion aid
that includes a number of features such
as lists members parameter in both quick info and word completion.
These features help you learn more about the code
they're using, keeps track of the parameters
you're typing, and as closer properties and
methods with only a few keystrokes.
For example here, IntelliSense provides
completion options for rallies when a type is known,
even if the e-mail name is not entered.
If I type empty I can find empty as a string.
IntelliSense can also provide completion options
for paths, operators, and indexers.
Navigating and exploring code is
an essential part of developer productivity.
We made it easier for you to visually inspect and
navigate the inheritance chain with the inheritance margin icons.
The inheritance margin icons are located in
the margins and clicking on the icons
will allow you to easily navigate
to your codes overrides and implementations.
Visual Studio also provides
inline parameter name hints for literals,
castle literals and object instantiations
prior to each argument and function
calls and inline type hints for
variables with inferred types and lands are parameter types.
To view inline hints,
you can either press Alt F1 or you can go into Tools, Options,
Text editor, C#, Advanced,
and you can go ahead and enable and
customize the types of hints that you want enabled in your editor.
We also made it easier for you to perform
data flow analysis on your code to help you
quickly determine how certain values might have
passed at a given moment with value tracking.
Value tracking is available if we right-click on
a member and select the track value source command.
The track value source command will
open the value tracking window,
allowing you to analyze results.
We created a new Razor editor for
development with MVC Razor pages and Blazor.
The new Razor editor is powered by LSP,
the Language Service Protocol,
which is an open-source model that defines how
editors can interact with different languages.
The LSP model allowed us to
enable more tooling support to the editor,
which ultimately enhances your developer productivity.
For instance, we added more
C# code fixes and refactorings such as Rename.
We also added more navigation support like Go To Definition.
We added item filtering in the IntelliSense completion lists.
These are some type highlighting has also
been updated to improve contrast,
general look and feel and usability.
For example, you may notice that
the C# background highlight has been removed.
This update makes it more clear when
something has been selected or highlighted.
We also updated the colorization options in Tools Options,
fonts and colors to be marked descriptive and customizable.
Hopefully you learned some new tips and tricks today.
As always, don't forget to provide feedback
through the Send Feedback tool in Visual Studio.
We would love to hear from you and feel free to
tweet at me @mika_dumont if you have
any other tips and tricks that you want to share or if you have
any feature requests that will enhance your productivity in .Net,
I would love to hear about it. Thanks for tuning in.