Browse by Tags
All Tags »
Patterns »
C# (RSS)
CLR 2.0 introduced IEquatable<T> which is an interface that allows for type safe equality comparisons. Previously, the best available method for comparing equality was the virtual Object Equals method. The method is loosely typed since
Read More...
Lately I’ve been playing quite a bit with F#. I have several hobby projects I’m working on that take up a bit of my time. But when I’m not playing around with F# I’m exploring ways to apply certain functional patterns to actual coding on the
Read More...
F# has a handy method called Unfold. Think of it as the logical opposite of an Aggregate function. Aggregates take a sequence of elements and convert them to a single element. An unfold method will take a single element and turn it into
Read More...
Sorry for the terrible pun in the title. I wanted to blog about developing an F# style Option class for C# and I couldn't resist. The basics of an Option class are very straight forward. It's a class that either has a value or doesn't.
Read More...
"If you implement equality in a child class, including operators, you must implement the equality operators in the base class." Unfortunately this is another case of learn the hard way but makes sense when you think about it. The below code snippet is
Read More...
I like Enums and use them frequently for options and behavior. To an extent I use Enum's to control behavior. For example enum Kind { Kind1, Kind2, Kind3 } class Example { private Kind m_kind; public int SomeAction() { switch (m_kind1) { case
Read More...
One action I find frustrating in C# is where a particular action needs to be taken based off of the type of a particular object. Ideally I would like to solve this with a switch statement but switch statements only support constant expressions in C# so
Read More...
Really this guideline is a bit longer but putting it all in a blog title seemed a bit too much. The full guideline should read: "If a generic class constructor arguments contain types of all generic parameters, provide a static method named
Read More...
Previously we discussed the opposite problem. This is a lesser but often more frustrating problem because there is no, AFAIK, built in solution for the BCL. However it's problem that can be solved once and reused with a generic solution. IComparable<T>
Read More...
It's often useful to ensure that actions occur on specific threads, in particular event handlers. Take Windows Forms for instance where all operations on a Control must occur on the thread it was created on. Typically this is not a problem
Read More...
Like most generic classes, I prefer to create Future instances through static factory methods which allows me to take maximum advantage of type inference. In addition to the 2 straight forward declaration of Func<T> and Action, the methods will
Read More...
In addition to Future<T> there is also the concept of Futures that don't return any values. Instead the perform the operation and return. Because there is no additional data to pass between the threads building an Empty Future is fairly
Read More...
If you read Jon Skeet's blog you'll notice he's been playing around lately with "push" style enumerators. Push enumerators are the concept of "we'll tell you when we're ready". This is different from IEnumerator<T> which is more of a pull; "ask
Read More...
Part 5 produced equality tests for Tuples. This section will add comparison support through the IComparable<T> interface. Implementing comparable is very similar to adding equality support. Once again there is a generic class available to make all
Read More...