Image for post
Image for post

Recently, when I was reviewing the new features that are going to be included in .Net 5, I came across an interesting one — C# Source Generators. This feature especially interested me since I have been using a similar approach for the last… 5 years and what Microsoft proposes is simply a deeper integration of this approach into the build process.

Further I’ll share my experience using Roslyn in code generation and I think this will help you better understand what exactly Microsoft offers and when you can use it.

First, let’s look at a typical code generation scenario. You have some external source of information such as a database, a JSON description of some REST service, another assembly (via reflection) etc. And using this information you can generate various types of source code such as DTOs, db model classes or proxies to REST services. …


Image for post
Image for post

It was a legacy enterprise project and I was asked to improve its “advanced” filtering capabilities.

Before they had something like this:


Image for post
Image for post

Almost 100% of asynchronous tasks that you deal with in your C# code are running or already completed regardless of whether you “await” them or not. This can be shown with the following example:

static async Task Main()
{
var task = GetValueAsync();
await Task.Delay(500);
Console.WriteLine("Awating...");
Console.WriteLine("Result is: " + await task);
}
static async Task<int> GetValueAsync()
{
Console.WriteLine("Async Start");
await Task.Delay(100);
Console.WriteLine("Async End");
return 42;
}

Output:

Async Start
Async End
Awating...
Result is: 42

As you see GetValueAsync finished before await but what if the behavior is not desired and you do not want a task to start executing until there is at least one “awaiter”? …


One of the Angular core concepts is the update of a component’s DOM in case the framework detects changes in its fields used in the template binding expressions. This is very convenient since it allows changing the component’s view just by updating the corresponding fields without any direct manipulations with DOM. At the same time, Angular leaves the way of how the component’s fields are updated to a developer and that works well in some simple scenarios since developers can quickly create components which meet all necessary requirements without the need to introduce any additional abstractions. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store