Poor Man's Custom Types with C# Using Aliases

For the sake of simplicity, I never implement custom types just for the sake of readability. I.e., I don't encapsulate int, string, decimal, and so on. This is because I find the cost being too high when writing, maintaining, and (OR) mapping all these types.

What I've just started doing in order to achieve the same level of readability, is using aliases like so:

using Birthday = DateTime;
using PersonId = Int32;
before the class declaration, but after the namespace declaration (so that one doesn't have to fully qualify the type names).

For complex generic types, the readability increases even more IMHO:
using StrangeDictionary = IDictionary<int, KeyValuePair<string, decimal>>;


1 comment:

  1. Wrapping a basic type in a class is not matter or readibility, but refactoring. Should you implement some logic in birthdate, you'll have to extend its class. Use an interface: you will be able to change the implementation.
    Sticking to DateTime seems simpler, but in effect it couples your classes with specific types