diff --git a/authors/martin/feed.rss b/authors/martin/feed.rss index 5b129ab..90df90e 100644 --- a/authors/martin/feed.rss +++ b/authors/martin/feed.rss @@ -5,7 +5,7 @@ https://daily-devops.net/authors/martin/ Recent content from Martin Stühmer on Daily DevOps & .NET en-US - Mon, 07 Oct 2024 15:19:57 +0000 + Fri, 11 Oct 2024 18:36:55 +0000 @@ -16,6 +16,8 @@ As developers, we’re often tasked with maintaining and modernizing legacy codebases that were written long before some of the best practices of today—such as nullability annotations—were available. While modern C# now supports nullable reference types, enabling us to avoid the dreaded NullReferenceException, introducing this feature to existing, large codebases can be a challenge. In this article, I’ll share my step-by-step approach for introducing nullability into a legacy .NET and C# project. You’ll learn how to apply nullability in a controlled, incremental manner using project-level settings, scoped annotations, and file/method-level directives, all while maintaining the integrity of your legacy codebase. After all, modernizing your code doesn’t have to be an all-or-nothing endeavor—gradual change is key to a successful transition. Let’s get started! + csharp + dotnet https://daily-devops.net/posts/buildinginsidevisualstudio/ diff --git a/feed.rss b/feed.rss index d53f980..4c3e677 100644 --- a/feed.rss +++ b/feed.rss @@ -5,7 +5,7 @@ https://daily-devops.net/ Recent content on Daily DevOps & .NET en-US - Mon, 07 Oct 2024 15:19:57 +0000 + Fri, 11 Oct 2024 18:36:55 +0000 @@ -16,6 +16,8 @@ As developers, we’re often tasked with maintaining and modernizing legacy codebases that were written long before some of the best practices of today—such as nullability annotations—were available. While modern C# now supports nullable reference types, enabling us to avoid the dreaded NullReferenceException, introducing this feature to existing, large codebases can be a challenge. In this article, I’ll share my step-by-step approach for introducing nullability into a legacy .NET and C# project. You’ll learn how to apply nullability in a controlled, incremental manner using project-level settings, scoped annotations, and file/method-level directives, all while maintaining the integrity of your legacy codebase. After all, modernizing your code doesn’t have to be an all-or-nothing endeavor—gradual change is key to a successful transition. Let’s get started! + csharp + dotnet https://daily-devops.net/posts/buildinginsidevisualstudio/ diff --git a/posts/buildinginsidevisualstudio/index.html b/posts/buildinginsidevisualstudio/index.html index 52975aa..e511161 100644 --- a/posts/buildinginsidevisualstudio/index.html +++ b/posts/buildinginsidevisualstudio/index.html @@ -39,7 +39,7 @@

Tags

VG Wort +How MSBuild builds projects - Visual Studio builds vs. MSBuild.exe builds
VG Wort
Gradually Introducing Nullability in Legacy Code: A Practical Guide for .NET and C#

Gradually Introducing Nullability in Legacy Code: A Practical Guide for .NET and C#

As developers, we’re often tasked with maintaining and modernizing legacy codebases that were written long before some of the best practices of today—such as nullability annotations—were available. While modern C# now supports nullable reference types, enabling us to avoid the dreaded NullReferenceException, introducing this feature to existing, large codebases can be a challenge.

In this article, I’ll share my step-by-step approach for introducing nullability into a legacy .NET and C# project. You’ll learn how to apply nullability in a controlled, incremental manner using project-level settings, scoped annotations, and file/method-level directives, all while maintaining the integrity of your legacy codebase. After all, modernizing your code doesn’t have to be an all-or-nothing endeavor—gradual change is key to a successful transition. Let’s get started!

Why Gradually Introduce Nullability?

Nullability annotations in C# allow us to specify whether a reference type can be null or not. This feature brings more type safety and reliability to your code, reducing the chance of runtime errors caused by null values. But here’s the challenge: introducing nullability into an existing, possibly large codebase and no clear code style, where methods and properties might be riddled with potential nulls, can result in an overwhelming number of compiler warnings. In such cases, it’s easy to give up on nullability altogether, leaving your codebase vulnerable to null reference exceptions. But it doesn’t have to be that way.

To address this, you can take an incremental approach. Rather than trying to make your entire codebase null-safe in one go, you can introduce nullability step by step—starting with new code and gradually refactoring old code. This method minimizes disruption and lets your team handle the transition without being flooded with warnings.

Step 1: Understanding Nullability Annotations in C#

In modern C#, a string is assumed not nullable by default, meaning it cannot contain a null value without a compiler warning. However, you can explicitly declare a string as nullable by using the string? syntax. Here’s an example:

string nonNullableString = "Hello";   // Can't be null, compiler will warn
 string? nullableString = null;        // Can be null, no compiler warning
 

The nullable string? type indicates that the variable may contain a null value, while the non-nullable string enforces that null values are not allowed.

The beauty of nullable reference types is that they make your intent clear, and C#’s compiler will help enforce this through warnings whenever there’s a potential for null dereferencing. And there is a huge list of possible nullable warnings, see Nullable reference types warnings @@ -52,7 +52,7 @@ -

VG Wort +

Tags

VG Wort VG Wort +GitHub Dependabot
VG Wort
C#

C#

Published blogs

Mastering .NET Project Properties: The `BuildingInsideVisualStudio` Flag

Mastering .NET Project Properties: The `BuildingInsideVisualStudio` Flag

In the ever-evolving world of .NET development, managing project configurations effectively is crucial for maintaining a clean and efficient build process. One of the less frequently discussed but highly useful properties is BuildingInsideVisualStudio. This property, when correctly utilized, can streamline your build process and ensure that your project is configured properly depending on the build environment. In this article, we’ll explore the BuildingInsideVisualStudio property with concrete examples and discuss best practices for using it effectively.

Manage Nuget Packages Centrally

Manage Nuget Packages Centrally

For over 12 years, NuGet package management has been part of the .NET ecosystem with direct integrations to various IDEs, CLIs and build systems. But a feature took 12 years before it appeared and certainly needs some more maintenance until it is mature!

.NET

.NET

Published blogs

Mastering .NET Project Properties: The `BuildingInsideVisualStudio` Flag

Mastering .NET Project Properties: The `BuildingInsideVisualStudio` Flag

In the ever-evolving world of .NET development, managing project configurations effectively is crucial for maintaining a clean and efficient build process. One of the less frequently discussed but highly useful properties is BuildingInsideVisualStudio. This property, when correctly utilized, can streamline your build process and ensure that your project is configured properly depending on the build environment. In this article, we’ll explore the BuildingInsideVisualStudio property with concrete examples and discuss best practices for using it effectively.

Manage Nuget Packages Centrally

Manage Nuget Packages Centrally

For over 12 years, NuGet package management has been part of the .NET ecosystem with direct integrations to various IDEs, CLIs and build systems. But a feature took 12 years before it appeared and certainly needs some more maintenance until it is mature!