Introducing CSharpSharp
Ever since C# 3.0 was released, I’ve been thinking about the possibilities opened by the extension methods. Extension methods allow developers to extend existing classes by providing them with additional methods. The beauty of this is that we can now create beautiful code APIs on existing classes without compromising its internal design. For example, an integer doesn’t care about dates and time values, but it might be useful to specify values such as 1 year, 3 months, etc. Without extension libraries, you’d have to use the TimeSpan constructor like this:
var oneYear = new TimeSpan(1, 0, 0, 0, 0, 0); var threeMonths = new TimeSpan(0, 3, 0, 0, 0, 0);
Not exactly pretty isn’t it? With extension classes, this can now become:
var oneYear = 1.Years(); var threeMonths = 3.Months();
Much better.
I’m a strong believer into offering a developer friendly API when developing my own applications. Now that we have extension methods, I can bring the same level of quality to existing code. That’s why I created CSharpSharp.
What is it?
CSharpSharp is a collection of extension methods and other classes grouped together in order to improve the API of the core of C#. The above example is only one of many other improvements I’ve implemented into the CSharpSharp libraries. The library is still relatively small, but I have plenty of other features ready to be added. The library is free to use for any project. I also plan on opening the source code depending on the feedback and reception in the developer community.
For more information, visit the project page, you’ll also find a link to download the library (libraries actually, there’s one specific for the Web).
If you would like to contribute to the project, I’m not looking for developer contributions right now, but I’m open to suggestions regarding new features.


Hey – nice idea. Here is what I am using for quite some time now:
public static class EventHandlerExtensions
{
#region Actions
public static void Fire(this Action handler)
{
if (handler == null) return;
handler();
}
public static void Fire(this Action handler, Action action)
{
handler.Fire();
if (handler != null) action();
}
public static void Fire(this Action handler, T value)
{
if (handler == null) return;
handler(value);
}
public static void Fire(this Action handler, T value, Action action)
{
handler.Fire(value);
if (handler != null) action();
}
public static void Fire(this Action handler, T1 val1, T2 val2)
{
if (handler == null) return;
handler(val1, val2);
}
public static void Fire(this Action handler, T1 val1, T2 val2, Action action)
{
handler.Fire(val1, val2);
if (handler != null) action();
}
public static void Fire(this Action handler, T1 val1, T2 val2, T3 val3)
{
if (handler == null) return;
handler(val1, val2, val3);
}
public static void Fire(this Action handler, T1 val1, T2 val2, T3 val3, Action action)
{
handler.Fire(val1, val2, val3);
if (handler != null) action();
}
public static void Fire(this Action handler, T1 val1, T2 val2, T3 val3, T4 val4)
{
if (handler == null) return;
handler(val1, val2, val3, val4);
}
public static void Fire(this Action handler, T1 val1, T2 val2, T3 val3, T4 val4, Action action)
{
handler.Fire(val1, val2, val3, val4);
if (handler != null) action();
}
#endregion
#region EventHandlers
public static void Fire(this EventHandler handler)
{
handler.Fire(null);
}
public static void Fire(this EventHandler handler, Action action)
{
handler.Fire();
if (handler != null) action();
}
public static void Fire(this EventHandler handler, object sender)
{
handler.Fire(sender, EventArgs.Empty);
}
public static void Fire(this EventHandler handler, object sender, Action action)
{
handler.Fire(sender);
if (handler != null) action();
}
public static void Fire(this EventHandler handler, object sender, EventArgs args)
{
if (handler == null) return;
handler(sender, args);
}
public static void Fire(this EventHandler handler, object sender, EventArgs args, Action action)
{
handler.Fire(sender, args);
if (handler != null) action();
}
public static void Fire(this EventHandler handler, object sender, T args) where T : EventArgs
{
if (handler == null) return;
handler(sender, args);
}
public static void Fire(this EventHandler handler, object sender, T args, Action action) where T : EventArgs
{
handler.Fire(sender, args);
if (handler != null) action();
}
#endregion
#region Special EventHandler Delegate
public static void Fire(this DoWorkEventHandler handler, object sender, DoWorkEventArgs args)
{
if (handler == null) return;
handler(sender, args);
}
public static void Fire(this DoWorkEventHandler handler, object sender, DoWorkEventArgs args, Action action)
{
handler.Fire(sender, args);
if (handler != null) action();
}
public static void Fire(this ProgressChangedEventHandler handler, object sender, ProgressChangedEventArgs args)
{
if (handler == null) return;
handler(sender, args);
}
public static void Fire(this ProgressChangedEventHandler handler, object sender, ProgressChangedEventArgs args, Action action)
{
handler.Fire(sender, args);
if (handler != null) action();
}
public static void Fire(this RunWorkerCompletedEventHandler handler, object sender, RunWorkerCompletedEventArgs args)
{
if (handler == null) return;
handler(sender, args);
}
public static void Fire(this RunWorkerCompletedEventHandler handler, object sender, RunWorkerCompletedEventArgs args, Action action)
{
handler.Fire(sender, args);
if (handler != null) action();
}
#endregion
#region Other Delegates
#if false // do not use these for now
public static void Fire(this Delegate handler, object sender, EventArgs args)
{
if (handler == null) return;
handler.DynamicInvoke(sender, args);
}
public static void Fire(this Delegate handler, object sender, EventArgs args, Action action)
{
handler.Fire(sender, args);
if (handler != null) action();
}
#endif
#endregion
}
Have fun!