Code Maze Author

Code Maze

This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.
Also find me here:



MY ARTICLES:

Hot Reload in ASP.NET Core Applications

In this article, we will dive into what hot reload is and how it revolutionizes our development workflow. We will review its features, origins, examples, and most importantly best practices. Let's start. What is Hot Reload Hot reload stands as a transformative feature...

How to Force Run .NET Application as Administrator

In this article, we will learn how to force run a .NET application as an Administrator. We will do that by modifying the application manifest file of our application to illustrate the whole process. [sc name="github"...

Noda Time in C#: Handling Dates and Time Zones

Noda Time is an open-source date and time library for .NET that gives each kind of value its own type: Instant for a moment on the global timeline, LocalDate and LocalDateTime for calendar values, and ZonedDateTime when a time zone matters. Handling dates can be...

How to Build a Query String for a URL in C#?

A query string is the ?name=value&name=value tail of a URL, and in C# we have six ways to build one. Four of them percent-encode the values for us. UriBuilder, the one most people reach for, does not. QueryHelpers.AddQueryString() is the short answer for an...

Strangler Fig Architectural Pattern in C#

In this article, we will discuss the use of the strangler fig architectural pattern. While the design can be applied to any programming language, we will focus on C# here.  [sc name="github"...

How to Read a String From a .resx (Resource) File in C#

In this article, we are going to learn how to read a string from a .resx file. While doing this, we are also going to understand what is going on under the hood. Additionally, we will follow some of the best practices on how to manage resource files, and lastly, offer...

Dynamically Adding Rows on a Form in Razor Pages

In this article, we will delve into ASP.NET Core forms and how to add rows to them dynamically. We'll use razor pages to create the form and SQLite as our database. [sc name="github"...

AutoMapper: How to Ignore Null Values When Mapping

To stop AutoMapper overwriting a destination value with a null from the source, add a condition to the mapping: .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null)). Members whose source value is null are then skipped, and whatever...

Unit of Work Pattern in C# With EF Core

The unit of work pattern groups every change a business operation makes and saves them together, in one transaction, so they all succeed or all fail. We will discover its advantages and disadvantages, and build an example implementation with Entity Framework Core....

C# String Contains Ignore Case: Substring Search

To find a substring while ignoring case in C#, pass a StringComparison value: source.Contains(needle, StringComparison.OrdinalIgnoreCase). Without that second argument, Contains() is case-sensitive, and there is no other switch that changes it. [sc name="github"...

Replace Line Breaks in a String in C#: ReplaceLineEndings

A line break in C# is not one character. It is any of seven sequences, and ReplaceLineEndings() is the one method that matches all of them: text.ReplaceLineEndings("\n") normalises a mixed string in a single call. String.Replace() and Regex.Replace() also do the job,...

Convert a Hex String to a Byte Array in C#

Convert.FromHexString() turns a hexadecimal string into a byte array in one line on .NET 5 and later. It accepts uppercase and lowercase digits, and it throws a FormatException for an odd length, a 0x prefix or any character that is not hex. In the rest of this...

Refactoring Dispensables in C#

In this article, we will explore refactoring dispensables in C#. We'll focus on identifying code smells and enhancing our code through practical refactoring techniques. [sc name="github"...

C# XPath: Select XML Nodes With SelectSingleNode

XPath is a path language for XML, and .NET exposes it through two methods on XmlNode: SelectSingleNode() returns the first node an expression matches, and SelectNodes() returns every one of them. An expression reads like a file path. /catalog/book walks down from the...