Back in 2009 I published a set of Extension methods called Generic Extension Methods. Over the years, hundreds of people have downloaded the source code and made their own projects with it. Now I’ve refined the extensions and repackaged them under Gateway Programming School.
There are extension methods for dealing with DBNull, getting/setting values of properties of an unknown typed object, and manipulating text.
Many of the methods exposed back in 2009 are no longer applicable as Microsoft has included many of the methods into the .Net Framework. This library will grow in the near future as it becomes actively used in the GPS projects.
You can get more info at the Project Site or on GitHub.
An extension method that will be making its way into the Generic Extension Methods library is one I want to share tonight. It’s for projecting an action N times. Why such a method doesn’t already exist baffles me!
public static T Project<T>(this T projected, int n, Action<T> action)
for (int i = 0; i < n; ++i) action(projected);
Usage could not be simpler, any object can be projected to the specified action any number of times.
public static int Method()
var value = 1;
return value.Project(10, i => i*=i);
The projection in this case yields 10^10 as the answer. Overly simplistic example, but makes the point succinctly.