Mark Mintoff My superpower is common sense


Extended Classes

Oft it is, that whilst coding I think to myself: "Self, wouldn't it just be awesome if this class I am making use of was simpler to use?" And the answer is always a definite yes. Hence, I will share with you four class "extensions" I developed, in order to make mgt;y life (well, my programming life) just a tad bit easier. These are:
  1. WeakReference with support for generics
  2. Dictionary which is easier to use
  3. Pair with support for generics
  4. Triplet with support for generics

WeakReference<T> The WeakReference class is one I have made extensive use of, in a complex Caching system which I developed, but immediately upon use, my first thought was that it needed to make use of Generics, as all the boxing and unboxing from an object into the type I want is colossally tedious. Hence, I developed this: Making use of this class allows for the exact same functionality as the original WeakReference, with the added benefit of having Typed parameters.
ExtendedDictionary<TKey, TValue> The Dictionary is easily my all-time favorite collection, however, I personally hate all the responsibility associated with checking ContainsKey all the time, and hence opted to create a Dictionary Wrapper in order to deal with this troublesome problem: This extension of the Dictionary, means that you no longer have to check for ContainsKey when attempting to extract a value from the Dictionary. You no longer have to check for ContainsKey when setting a value in the Dictionary. becomes and now becomes simply: Use it wisely. I don't want to be responsible for any gigantic logical faults.
Pair<A, B> and Triplet<A, B, C> System.Web introduces to us the Pair and Triplet objects, which at first glance are absolutely brilliant. But then again, they have no generics support in-built. In addition to that, for some strange reason the Pair and Triplet classes exist in System.Web. I don't much fancy adding a reference to System.Web in Class Libraries where that reference does not belong, so on to making my own: and The concept here is pretty simple; classes which contain 2 or 3 values respectively. The override of Equals and GetHashCode is necessary if you have any intention of using Pair or Triplet as a key in a Dictionary.
That concludes my outlining of four extended classes out of the many extensions and helper methods I have created to make my life slightly easier. I trust you will use them well and I hope they will bring you the same added simplicity to coding that they brought to me.
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)