Immutable Collections and Compatibility with Existing Frameworks

When developing my immutable collections library, I spent a lot of time on usability.  After all, if a library is not useful then what’s the point? A big portion of usability is being able to work with existing frameworks and technologies.  For .Net and collections that means items like Data binding, LINQ etc …  Without…

3

Gotcha: Generic overload resolution when called generically

Both VB and C# have a feature of generic overload resolution that is fairly helpful and yet a source of gotchas.  Lets say you have two methods with the same number of arguments.  One method has arguments with generic types and the other does not.  For Example: class C1<T> { public void F1(int ival) {…

1

Design Guidelines: Provide type inference friendly Create function for generic objects

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 Create on a static class of the same class name as the generic…

3

Have an IComparer<T> but need an IComparable<T>?

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> has all of the methods necessary implement IComparer<T>.  To work around this we’ll create…

0

Tuples Part 8: Finishing up

There are only a few missing features from our tuple implementation.  Mainly FxCop compliance, debugging support and test case code.  The actual functional work is complete.  The one issue with FxCop compliance is the chosen names.  Namely using A,B etc.  FxCop, rightly, believes names should have more value.  Accordingly, calling the generic argument corresponding to…

2

Tuples Part 6: Comparing

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 of the comparison decisions for us; Comparer<T>.  The implementation will compare objects in a left to right fashion. …

3

Tuples Part 5: Equality

Part 4 left us with a reusable, abstract and inference friendly Tuple class.  The next step is to be able to test for Tuple equality.  For the Tuple implementation, two tuples will be defined as equal if all of their members are equal.  Seems fairly straight forward.  The trick is in the implementation.  In addition…

2

C# Lambda Type Inference

One of the limitations of C# type inference is that you cannot use it to infer the type of a lambda expression.  For example, the following code will not compile var f = () => 4; Normally this is not too much of an issue because you can just explicitly declare the type of the…

1

Type Inference and IEnumerable

This is somewhat of a follow up on a previous post I did on the difference between IEnumerable(Of T) and the IEnumerable interfaces.  I’ve seen several people type in the following code and wonder if there was a fundamental bug in the type inference code. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)…

2

Names of Anonymous Type Members

Recently I was asked how can you get a list of anonymous type member names given a query of anonymous types.  The quick answer is that you can use a quick bit of reflection to get back the names.  Public Function GetAnonymousTypeMemberNames(Of T)(ByVal anonymousType As T) As List(Of String) Dim type = GetType(T) Dim list…

1