My Blog

Here you can find my private notes about programming that I wanted to share with you. Feel free to filter based on the topic you want or search for something specific.

    A "work in progress"-list with the Docker commands I use the most

    Since the start of 2019, I have been using Docker containers in the projects I work on. Working with a command line tool (Windows PowerShell, Shell, etc.) is essential when creating new containers. Below is a list of the commands I use the most:

    Read the complete article

    Deserialize a JSON string into a C# object and set custom values into a property of that object

    This week I had to deserialize a JSON string into a collection of C# objects. The class of these objects contained not only the properties that map directly to the JSON properties but also an extra property which I wanted to fill with values based on the values of other properties of the object.

    Let us consider the following simple POCO class and its container, which is a simple array of Students:

    Read the complete article

    How to use the fileinputname parameter inside your template items in Visual Studio

    A Visual Studio Item Template allows us to generate new files with code, so that we avoid having to manually create them. This automatization is very practical when we need to create similar classes more than one time. A template is being offered as option in the “Add new item” dialog of Visual Studio:

    Add new item dialog in visual studio

    Read the complete article

    How to skip the mapping between properties of a source and a target object in AutoMapper

    As I did in my previous article, I focus again on the AutoMapper framework.

    When I map one object to another, I often deal with a destination object that contains LESS properties than the source object. If I take no action, an exception is going to be thrown. For that we will have to declare the skipped properties by using the DoNotValidate method when we define the mapping (CreateMap) between the two objects:

    Read the complete article

    Use a custom function when mapping one property to another with Automapper

    Automapper is a handful tool for mapping the properties of two different type objects together. Such mappings are very common when you are dealing with a multi-tier architecture in your program. For example you want to map the entity object, which contains data from the database, with the UI-model object of your WebApi action.

    For basic mapping examples refer to the Automapper documentation. In this article we will consider the following advanced example:

    For that you need a mapping between two properties of different type and also a function that runs every time to do this transformation:

    Read the complete article