Browse by Tags
All Tags »
Generics (RSS)
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
Read More...
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:
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...
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.
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...
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.
Read More...
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
Read More...
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.
Read More...
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
Read More...
Quick follow up to my earlier post . Fixing this issue in C# is even easier because of the existence of iterators. public static IEnumerable < object > Shim(System.Collections. IEnumerable enumerable) { foreach ( var cur in enumerable) { yield return
Read More...
IEnumerable(Of T) is a huge step up in the 2.0 framework from the original IEnumerable interface. It provides a typed enumeration which eliminates lots of nasty casts. The best part is that IEnumerable(Of T) is backwards compatible with IEnumerable (it
Read More...
This discussion is building upon a previous post on how to acquire an anonymous type ... type . The next question is, how can you cast an arbitrary object into an anonymous type? At a glance this doesn't seem possible as you cannot directly express the
Read More...
Quite awhile back I posted about how to create a re-usable singleton pattern in .Net. Link is here . A bit of time has passed and I've altered the pattern a bit. The reasons for the change are some new type inference patterns and FxCop cleanliness. The
Read More...