Craig's Utility Library

Contains more utilities than Batman's belt


Project maintained by JaCraig Hosted on GitHub Pages — Theme by mattgraham

I'm Batman

Have you ever thought about why Batman is as effective as he is? I mean sure he's rich, in better shape than any of us will ever be, and is a master at martial arts, but what almost always wins the day for him is that utility belt. It's the never ending supply of gadgets and utilities that he can use in the appropriate situation that really saves the day. And Craig's Utility Library is the same for programmers.

With .Net we have a number of built in classes and functions to help make a programmer's life easier, but let's face facts, they didn't think of everything. Craig's Utility Library tries to fill in some of those gaps (or at least the ones that I've run into). It comes with a couple hundred extension methods, built in data types such as a BTree, priority queue, ring buffer, etc. And that's just the DataTypes namespace. When you add it all up, Craig's Utility Library is one of the largest set of utilities for .Net out there.

C'mon, Deckard. Show Me What You're Made Of.

So let's look at a couple of examples of where these might come in handy. Have you ever been trying to download a web page?

string Content=new Uri("http://www.duckduckgo.com").Read();

That's it. Well that and adding the Utilities.IO.ExtensionMethods namespace. Want to format a string as a phone number?

string PhoneNumber="5555551010".FormatString("(###)###-####"); //Becomes (555)555-1010

Want to remove all items from an ICollection that are greater than 5?

ICollection<int> Values=new int[]{1,2,3,4,5,6,7,8,9,10}.Remove(x=>x>5); //Will return 1,2,3,4,5

Want to load every DLL from a given directory and then search it for any class that uses a specific interface and create an instance of it?

IEnumerable<IMyInterface> Classes=new DirectoryInfo("./MyAssemblies/").GetObjects<IMyInterface>();

Want to change an image into ASCII art?

using(Bitmap MyImage=new Bitmap("FileToLoad"))
{
   string ASCIIArt=MyImage.ToASCIIArt();
}

And that's just a couple examples for the extension methods. Want to connect to a database but hate ADO.Net? Use SQLHelper:

using(SQLHelper Helper=new SQLHelper("SELECT * FROM MyTable",System.Data.CommandType.Text,"DatabaseConnection"))
{
   Helper.ExecuteReader();
   while(Helper.Read())
   {
      int Value1=Helper.GetParameter("Value1",0);
      string Value2=Helper.GetParameter("Value2","");
   }
}

This utility library contains code for caching, compression, configuration, data mapping (think AutoMapper), encryption, IO, an IoC container, LDAP/AD querying, Math helpers, image manipulation, a micro ORM (somewhere between BLToolkit and PetaPoco in terms of speed), a full blown ORM, a profiler, randomization helpers, extension methods to help with reflection, a set of classes that allow you to do AOP, DataAnnotations additions for validation, a number of file formats, as well as web related helpers.

That's Not a Knife, This is a Knife

Still don't think that it's a lot? Here's just a small list of the extension methods: Utilities.DataTypes.ExtensionMethods

Keep Going...

Yeah, there's more...

Utilities.Math.ExtensionMethods

OK, now we're done... With the first half of the list...

Utilities.SQL.ExtensionMethods

Utilities.Compression.ExtensionMethods

Utilities.Encryption.ExtensionMethods

Utilities.IO.ExtensionMethods

Want to cry yet?

Utilities.Web.ExtensionMethods

Utilities.Image.ExtensionMethods

Just a bit further

Utilities.Error.ExtensionMethods

Utilities.Reflection.ExtensionMethods

Utilities.Environment.ExtensionMethods

Now we're done... With the Extensions...

Seriously, if you can't find something in here that would make your life a bit easier, you're not doing .Net development.

Where Are My Dragons?

The nice thing about this library is I let you pick what you need. Want to just use the DataTypes and IO namespaces? Not a problem. Want everything? I have a DLL for that also. The easiest approach though is to use NuGet:

Entire library (with command from package manager console):

Individual namespaces (with command from package manager console):

You're Still Here? It's Over. Go Home.