C# Traps and Traps

Recently, on behalf of my employer, I spoke at the IT Academics Day, a small .NET conference organized by the West Pomeranian University of Technology. Together with Mateusz, we have presented some of the traps that a C# developer might encounter and how to recover from those. I would like to share three of ten such traps in today’s blog post, the rest will follow.

When inheritance is dangerous

The first one is a dangerous design trap, a bomb with a long fuse. Let’s take a look at the following code:

internal class BaseData
{
   protected string data = null;

   public BaseData(string data)
   {
       this.data = data;
       this.InitializeState();

       Console.WriteLine("BaseData created");
   }

   public virtual void InitializeState()
   {
       // Some basic initialization logic.
   }
}

Do you see anything dangerous yet?

Continue reading “C# Traps and Traps”

Using validation attributes in .NET Core

There are a number of ways you can implement validation of your forms, models or uploads. One of the most common methods of doing that is using validation attributes. Not only are they very easy to use, they can also be customized freely according to your business’ requirements. Today we’ll take a closer look at how to use them based on a real-life example from our project.

Continue reading “Using validation attributes in .NET Core”

Creating a simple Content Management System

I have been working on creating a content management system (CMS for short) for troika-game.net. One of my tasks was to implement a way for the admin (who may not be a software engineer himself) to add, edit, and delete news from the home page. It is a very much needed (while still being rather basic) feature of our app. It requires the understanding of several aspects of ASP.NET Core MVC, so it’s a great way to learn the technology and besides – you got to start somewhere!

Continue reading “Creating a simple Content Management System”