This page shows the posts published with the category '.NET'

Stop using IntPtr for dealing with system handles

When using system handles such as file handles, process handles, or any other handles provided by the kernel, you should take care to release them correctly when you don't need them anymore. The native APIs often provides a method to get a handle and a method to release it, plus sometimes a few methods to work with the resource. For instance, you can get a file handle using the method CreateFile, release… [read more]

Creating a FontAwesome bundle with only the icons you use

FontAwesome contains thousands of icons, but you often use a very small subset of those icons. For instance, I only use 15 icons on this website. So, why do you want your visitors to download hundreds of icons they won't use. One solution is to create a custom bundle that contains only the icons you actually use. You can reduce the bundle size from a few hundred kB to a few kB (6kB on this website).… [read more]

String comparisons are harder than it seems

Comparing strings is different from comparing numbers. 2 numbers are equal if their values are identical. For instance 1 is equal to 1, and 1 is not equal to 2. That's trivial. When it comes to string, things are different. For instance, do you want a case-sensitive comparison? What about the different ways to write the same letter. For instance, the letter ß is common in German, but it's also possible to… [read more]

Computing code coverage for a .NET Core project with Azure DevOps and Coverlet

Creating automated tests is important to be sure your application behaves as it should. The more tests you write, the more use cases are covered. Sometimes it can be hard to know which parts of the application are well tested, and which ones are not. That's why code coverage is interesting. It can be a useful measure to detect potential risk areas in the application (i.e. the most complex methods with the… [read more]

Writing a language-agnostic Roslyn Analyzer using IOperation

In a previous blog post, I explained how to write a Roslyn Analyzer for C#. This analyzer uses the C# syntax tree and the semantic model to detect some patterns and reports warnings. Then, the code fix can replace nodes in the C# syntax tree. So, the analyzer cannot be used for VB.NET as the syntax tree is different. This means you would need to create and maintain an analyzer for C# and another one for… [read more]

Loading stylesheets asynchronously using a TagHelper in ASP.NET Core

In a previous post, I've talked about inlining a CSS file in the html page. In term of performance, this is important to inline the critical CSS. However, the rest of the styles of the page doesn't need to be downloaded immediately. For script elements, you can simply add the attribute async to instruct the browser to load the resource asynchronously. For stylesheets, there is no equivalent. You have to… [read more]