How to Find the Caller Method in C#
In this article, we will learn how to find the caller method in C#. We will also learn about scenarios in which this information could be useful and how to retrieve it. [sc name="github"...
MY ARTICLES:
In this article, we will learn how to find the caller method in C#. We will also learn about scenarios in which this information could be useful and how to retrieve it. [sc name="github"...
In this article, we will take a look at testing if our code throws exceptions, why we want to do that, and how to do it in the MSTest, NUnit, and xUnit frameworks. [sc name="github"...
TimeSpan is a value type that represents a length of time rather than a point in time. A DateTime says when; a TimeSpan says how long. It stores one 64-bit tick count, where a tick is 100 nanoseconds. That single value is what makes the type cheap, comparable and...
In this article, we will learn and implement five different ways to return multiple values from a C# method. Returning multiple values to a...
 In this article, we will learn how to read database connection strings from different configuration sources in .NET applications. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/aspnetcore-features/HowToReadConnectionStringsInDotNet"...
These four are one inheritance chain, not four alternatives. IEnumerable<T> can only be iterated, ICollection<T> adds Count and mutation, IList<T> adds indexing, and List<T> is the concrete class that implements all of them. So the choice is...
This article will look deeper into Enums in .NET and how we can improve them with the SmartEnum library. Let's begin! What Are Enums? Enumeration...
In this article, we will learn about situations where we may need to convert a file into a byte array. Additionally, we will learn two ways to perform the conversion in C#. If you want to learn how to convert a byte array to a file, check out our convert byte array to...
In this article, we are going to learn about passing output parameters to stored procedures with Dapper. Stored procedures are a great way to improve the performance, security, and usability of our code. They bring many advantages over relying on our application code...
In this article, we will learn when the "call is ambiguous" error happens, why the error happens, and how to work around the issue. There are still so many legacy projects using older versions of EF Core, and in those projects, this error can cause a lot of headaches...
In this article, we discuss how to create guard clauses, how they differ from user input validation, and how to improve our guards by writing clean guard clauses leveraging the GuardClauses library. [sc name="github"...
In this article, we will be learning how to compare two JSON objects in C#. Let's dive in. Data Preparation For this article, we will be using a...
In this article, we will look at the power of the File and FileInfo classes used for file manipulation in C#. We'll uncover the similarities and differences between these two classes and why we would want to use one over the other. [sc name="github"...
In this article, we’re going to learn how to change Swagger base uri in ASP.NET Core Web API. So let's start. Swagger and Base Uri Swagger is an...
In this article, we will discuss how to determine whether two date ranges overlap in C#. We will explore how to achieve this result using the DateOnly and TimeOnly records and then, we're going to beautify our implementation with a custom class representing date...
MultipartFormDataContent is the HttpContent subclass that builds a multipart/form-data request body in .NET. We add one part per field or file, and it handles the boundary string and the per-part headers for us. Every part is itself an HttpContent. A text field is a...
This article will examine how we can get a formatted JSON representation of our C# objects using two popular libraries - Json.NET and System.Text.Json. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/json-csharp/HowToGetFormattedJson"...
Introduction In this article, we'll look at ways to use dependency injection with constructor parameters in .NET Core. Dependency injection (DI) with constructor parameters is a way for us to pass the things our class needs (depends on) when we create a new instance...
Reading a key a Dictionary<TKey, TValue> does not hold throws a KeyNotFoundException. When a missing key is an ordinary case rather than a bug, GetValueOrDefault() is the method we want: it returns default(TValue) instead of throwing, and its second overload...
In this article, we are going to learn about the various patterns to implement asynchronous programming in .NET. .NET has had in-built support for asynchronous programming since the release of .NET Framework 1.1. It has been through various improvements over the...