Code-review is important in our daily development. Some developers may spend lots of time on learning new features of the languages, DDD, distributed system or some fancy stuff but the first thing we should keep in mind is we need to write the robust, maintainable code. Here are some tips from my recent code-review and I hope it would be helpful for you.

NullReferenceException series

The is really annoying. The best way to avoid it is to check if the variable is null before you use it. Here are some potential issues. I also include other exceptions such as here.

Always initialize the collection when you declare it

Recently, I participated the MVP Global Cloud Skills Challenge, which allows all Microsoft MVPs to be competing on a global stage. As you know, Microsoft Learn is a free learning resource site for everyone who wants to learn Microsoft technologies. I have advocated it many times via my social network. Today, I would like to share what I learned from #TheMVPChallenge.

First, I would say the content of Microsoft Learn is super high-quality and it is so easy to follow the instructions to create your immersive learning experience. Before the MVP Challenge, I have been immersed in Microsoft Learn for…

Microsoft introduced Source Generators in the latest C# version. It is a new feature that allows us to generate source code when the code compiles. In this article, I will walk you through four ways that can generate source code to simplify our daily jobs. Then you can choose the proper way for various scenarios.

Good developers are lazy developers because they don’t want to repeat the code over and over again. In the .NET world, we have such ways to help us generate code:

  • Code snippets.
  • Reflection.
  • T4 Template.
  • [New] Source Generators in .NET 5.

Maybe you have more…

CITANZ Event End-of-Year Carnival

Around two month ago, I was awarded Microsoft MVP for the 5th year. I would like to take this opportunity to reflect my last 3 years. After one year of preparation, I migrated to New Zealand from China in 2018. That was a huge change to me and my family. I would like to let you know how huge the impact is to have such amazing community support. This story is about CITANZ (Chinese IT Association NZ) and myself.

First of all, I would like to appreciate the Microsoft MVP program. Initially, I just published some blogs regarding my .NET…

Azure Automation is a service of Azure that allow us to automate the Azure management tasks and to orchestrate actions. It is widely used in operations to help us save time and reduce the human errors. Recently, I just created the scripts to turn on/off the virtual machines on schedules to save cost. If you have the same requirement, feel free to copy/paste the scripts and save your money.

I assume you already have your Azure subscription. And you may have a few VMs deployed in Azure, but we know the price of VMs is quite expensive and it would…

Recently, I am using Xamarin to develop a mobile app for Android. In the app, there is a page that asks the user to input phone numbers twice to make sure the number has been typed correctly. The user is not allowed to copy/paste. So I need to implement a custom control that can disable copy/paste features.

Even we can use C# to develop Android with Xamarin, we have to gain enough native development skills to complete this goal. I also understand for a new Xamarin developer, it would be tricky to find a solution related to native functionalities. So…

ASP.NET Core is a cross-platform, high-performance framework for building cloud-based applications. One benefit is we can run ASP.NET Core apps on Linux, and it is easy to deploy as Docker images. One more thing, the price is good. Let us compare the price tiers of Azure App Service:

Web App on Windows:

Web App on Linux:

In part 1 of this article, I used Azure DevOps to deploy my ASP.NET Core app to Azure Web App on Linux. The next part is to publish the same web app to Azure Web Apps for Containers. I do not need to re-emphasize the benefits of the container. You can find bunches of documents that promote it. So I just would like to show you how to leverage the Azure DevOps Pipelines to build the web app as docker images then push it to Azure Container Registry, then publish it to Azure Web Apps for Containers.


First, we need…

I found an interesting project — GildedRose-Refactoring-Kata on GitHub. It provides a starting code for refactoring exercise in a bunch of programming languages. The principle is we should create enough unit tests that can cover all cases(especially for the edge cases), then start to refactor the code. Let us try to do some exercises.

The original project has a huge method that contains lots of blocks to update the Item properties. Regarding the refactoring, there is a limit based on the requirement - "do not alter the class or Items property". That is kind of trap because…

With EntityFramework Core, we can use attributes or Fluent API to config the model mappings. One day I just got a scenario that needs a new mapping style. There is a system that generates lots of data every day and it needs to store the data per table for each day. For example, the database looks like:

All the tables have the same structure. So how could we change the mapping to avoid creating lots of models?

In this article, I will show you how to change the mapping to handle this situation. …

Xiaodi Yan

Microsoft MVP / .NET, Azure Developer / Learner

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