Category: Development

  • Deep clone an object with C#

    Cloning is a common thing I need to do in my C# project. The most common case I use this is with my Entity Framework projects. I first fetch my object using a standard Linq query.

    Once I have this object, EF is now tracking any changes to the object. I want a duplicate object of this so I can track a before and after state, so I want to clone the fetched object. To do this I use JSON.Net nuget package.

    (more…)

  • Why you should use strict with JavaScript

    Many people “dislike” JavaScript for reasons that I cannot understand. I like it and it serves a purpose. JavaScript can be a very forgiving language. By that I mean it let’s you get a way with things that other languages, that are a little stricter, would not. This is where the “use strict” comes into play.

    (more…)

  • What is the difference between String and string in C#?

    Short answer: nothing. string is an alias to System.String. This also holds true for int and System.Int32.

    If you want my personal preference I always use the lowercase version aka the alias. Why? Because I don’t need to add the following reference: using System; in each file. I know, it’s a little OCDish, but what can I say…

  • Updating all npm packages in a Node.js project

    I have two common scenarios where I want to update my npm packages. First, my existing project needs a package update or secondly I’ve started a new project and since I’m lazy I’ve copied my package.json file from one project to this project. I’ve found two different ways to perform this.

    1. Changing the versions to * in my packages.json
    2. Using the npm-check-updates package

    Let’s examine in more details each way.

    (more…)

  • Passing/reading command line arguments with Node.js

    It’s quite common when running an application to want to pass arguments to the program to define how it should run when executed. This is no different then with Node.js. To accomplish this I like to use one of two ways:

    1. Reading the JavaScript array node js process.argv and manually parsing the variables
    2. Using an npm library such as minimist that helps simplify and (in my opinion) parses them into a nice JavaScript variable

    Let’s take a look at both ways.

    (more…)