Craig’s Utility Library 3.2 Released

9/3/2012

A new version (3.2) of Craig's Utility Library has been released. It's not a huge release but it adds a number of fixes, speed increases, and methods to make your life a bit easier. However there was one major addition with regard to randomization. This time a much more robust set of classes and extension methods dealing with randomization. It adds the ability to randomly generate company names, male/female names, cities, states, zip codes, phone numbers, even entire data classes by simply calling either the Next<T>(...) or NextClass<T>(...) extension methods that were added. In fact the Next generic extension method has built in generators for bool, decimal, double, float, byte, char, int, long, sbyte, short, uint, ulong, ushort, DateTime, TimeSpan, Color, and string (with a ton of other string generators). In fact with the new classes and extension methods you can do something like this:

   1: public class RandomTestClass
   2: {
   3:     [IntGenerator]
   4:     public int A { get; set; }
   5:  
   6:     [LoremIpsumGenerator]
   7:     public string B { get; set; }
   8:  
   9:     [FloatGenerator]
  10:     public float C { get; set; }
  11:  
  12:     [IntGenerator(1, 100)]
  13:     public int D { get; set; }
  14: }

And call NextClass and have a newly generated RandomTestClass object given to you.

Past the new randomization classes/extension methods, a number of updates, speed increases, and fixes were implemented on the SQLHelper, MicroORM, and ORM classes. For example, you can now add parameters in batch to the SQLHelper class by simply calling the AddParameter function. (For example if you have "SELECT * FROM Table WHERE ID=@0 and Value=@1" and you used AddParameter(10, "This is a string") then it would put the value 10 in for @0 and "This is a string" for @1 (note that it would do that as a parameter, it doesn't do string concat).

On top of that a number of extensions to make life easier were added, such as Times which will run a function/action the specified number of times, so 100.Times(x=>x) creates a list of integers going from 1 to 100. On top of that, I ???ve added:

  • A RingBuffer class
  • Google API class for pulling static maps
  • LevenshteinDistance extension for strings
  • extension method to convert Dictionary and NameValueCollections classes to query strings
  • UserIPAddress and IfModifiedSince extension methods for HttpRequest
  • RelativeTime extension which expresses the difference between a DateTime and some Epoch as a string
  • updated the BlogML code to allow exporting
  • added ReadAll and ReadAllBinary extensions for Stream objects
  • and a number of other items.

Future of the Library

I've recently had a number of requests for additions as well as a couple other questions regarding 3rd party libraries. With regard to 3rd party libraries, I'm at a bit of a cross roads at the moment. When I started the library I wanted to make it so that it only relied on .Net and maybe a couple Win32/COM APIs. There were a couple of reasons for not using 3rd party libraries. I mean part of the issue was the fact this library is sort of a learning experience for me. When I want to try out a concept, I usually do it here. Hence I have no desire to use something like AForge for simple image manipulation. I want to build that myself to learn about the subject. But the main reason for not using 3rd party libraries was that at the time, it was a pain.

Keeping libraries updated and working between updates took a lot of work, requiring users to pin to a specific version of a library was difficult, putting out updates of your product became a pain, etc. Now we have NuGet. NuGet makes all of those issues simple to handle (and I don't think I would lose any users as I actually get more downloads from there than Codeplex at this point). On top of that we're now in a weird bizarro world where the .Net guys (well the web portion anyway) are now using open source libraries...

So let's assume I say OK to the 3rd party libraries, what libraries? Because not only is Json.Net a possibility (and it's MIT license, so that works), but ServiceStack has some advantages. Then you have other libraries that are getting added into the "blessed" mix (DotNetOpenAuth, etc), which is probably only going to expand in the future... But then does it even matter if something gets the nod from Microsoft? Personally I say no. I tend to remove all of their prepackaged libraries and start from scratch anyway. That being said, I actually do use Json.Net, but I can't guarantee that I will continue to do so in the future. In fact I tend to swap out libraries without giving it a second thought...

Anyway, long story short, I'm not going to be adding 3rd party libraries directly into the library. However I am looking at ways to allow people to attach 3rd party libraries to the system. It will probably be some combination of MEF, IoC, and extension points. I'm still working on the design though. As far as requests for additions, I welcome people to fork the library and make additions. However most changes that I make are due to my day to day work so if it's in line with what I'm already doing, I'll probably add it. If it's not, it might take a while for me to add it. But if you fork the project and make additions, I'll most likely accept them.



Comments