Home
Releases
Discussions
Issue Tracker
Source Code
Stats
People
License
RSS RSS Feed
Search Wiki:
Project Description
The .NET Extension Library adds common functionality to .NET's system libraries. Most new features are added to existing types via extension methods. The rest of the features are either new classes or improvements to existing classes (such as the introduction of an ICache interface for greater abstraction).

The goal is to provide a standard set of useful functionality to your existing toolset.

Here's a brief example that demonstrates 2 extensions, as well as the improved cache API:
User user = CacheFactory.GetInstance.Fetch("user.{0}".Sub(userId), () => _dataStore.GetUser(userId), 3.DaysFromNow());

1 - CacheFactory returns an instance of ICache, which helps decouple your code from the underlying caching implementation (it currently returns an HttpRuntime.Cache object)
2 - Fetch is a mix between Get and Insert - if Get returns null, the Func<T> callback is invoked, stored and returned
3 - The string.Sub() extension method is a short alias to string.Format
4 - int.DaysFromNow() is one of many neat integer extension methods that make it easier to deal with dates

Contribute
The best way to contribute is to submit your own extensions to the project. You can do so by opening an Issue and providing the extension code (and ideally accompanying nunit tests). The exact process for new extensions to be accepted isn't particularly well-defined. We'll likely use a mix of popularity (vote for extensions you want to see implemented) as well as common sense. As a general guide, we are seeking extensions that are simple and useful beyond some edge case.

Early Beta Warning
The library is in a very early beta. The code is very simple, and relatively well covered by equally simple tests; however, none of the behavior is currently locked. In other words, it's possible for the behavior of some extension methods to change (string.Proper() comes to mind), as well as having methods removed or added

Download
You can download the source, directly from the repository at: http://www.codeplex.com/nxl/SourceControl/ListDownloadableCommits.aspx
A compiled version will be made available in the future (once the project has matured a little)
Last edited Jul 9 at 7:39 PM  by KarlSeg, version 6
Comments
mstrobel wrote  Jul 15 at 1:50 PM  
Nice work so far. I've posted some suggestions in Discussions.

Woil wrote  Jul 15 at 5:02 PM  
It seems that a lot of these same things are being provided in the Umbrella project. Have you considered trying to work with them? It seems silly to me that there would be two separate projects with very similar support.

shanselman wrote  Jul 17 at 12:20 AM  
+1 to merging with Umbrella or Rhino Commons. There's a LOT of Utility Classes out there. We should conflate the ones that are spiritually the same.

simone_b wrote  Jul 18 at 3:41 PM  
Agreed, it's a waste of good work to spread all this stuff among several projects, mostly because they almost to the same things in the same way.

nesteruk wrote  Jul 31 at 6:44 PM  
How about writing extension methods for {{double}}, {{int}}, etc. that would replace those length {{Math.}} functions by something simple. For example, it's a lot easier to write {{x.pow(2)}} than {{Math.Pow(x, 2)}}. In addition to making these additions, it would be possible to add functions that {{System.Math}} misses - such as, e.g., secant.

GSerjo wrote  Aug 23 at 11:54 PM  
I use following

public static class EventExtensions
{
public static void RaiseEvent<T>(this object sender, EventHandler<T> eventToRaise, T eventArgs)
where T : EventArgs
{
EventHandler<T> eventCopy = eventToRaise;

if (eventCopy != null)
eventCopy(sender, eventArgs);
}

public static void BeginRaiseEvent<T>(this object sender, EventHandler<T> eventToRaise, T eventArgs)
where T : EventArgs
{
EventHandler<T> eventCopy = eventToRaise;

if (eventCopy != null)
{
foreach (EventHandler<T> handler in eventCopy.GetInvocationList())
{
EventHandler<T> handlerTemp = handler;
handler.BeginInvoke(sender, eventArgs, ar =>
{
try
{
handlerTemp.EndInvoke(ar);
}
catch (Exception ex)
{
LogManager.GetLogger(typeof (EventExtensions)).
Error(ex);
}
}, null);
}
}
}
}

GSerjo wrote  Aug 23 at 11:57 PM  
another my extension

public static class EnumExtensions
{
public static string ConvertToString(this Enum value)
{
if (value == null)
throw new ArgumentNullException("value");
Type type = value.GetType();
FieldInfo fieldInfo = type.GetField(Enum.GetName(type, value));
var descriptionAttribute =
(DescriptionAttribute) Attribute.GetCustomAttribute(
fieldInfo, typeof (DescriptionAttribute));

if (descriptionAttribute != null)
return descriptionAttribute.Description;
return value.ToString();
}
}

Updating...