Skip to main content


Showing posts from March, 2013

Formatting TFN and ABN

I'm not entirely sure if I've mentioned this before BUT I happen to LOVE extension methods.

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

I recently had to write some of them up for Formating TFN and ABNs.

Here are the TfnAbnExtnesion Methods. (I could have also used regular expression to accomplish this but I chose to keep it simple/maintainable.)

public static class TfnAbnExtensions
/// <summary>
/// Formats the TFN.
/// If the length is 9 char, return XXX XXX XXX
/// If the length is 8 char, return XXX XXX XX
/// </summary>
/// <para…