advanced web statistics

Generic LOList is Serious Business (This are Serious Post)

1/25/2008 11:30:54 PM

So LOLCode is the latest programming meme.  If you want to either waste a lot of time or kill time and get paid for it (in-house development job) I highly suggest it. I thought I'd have a little fun and write some code that is 100% useless yet 100% functional at the same time.  Ladies and gentleman I present to you: LOList<T>.

public class LOList<T> : List<T>
{
   public bool HazFilez
   {
      get { return Count > 0; }
   }
   
   public T Gimmeh(Predicate<T> match)
   {
      if (match == null)
         throw new ExceptionWTF("match", "WTF?");

      for (int i = 0; i < Count; ++i)
         if (match(this[i]))
            return this[i];

      return default(T);
   }

   public LOList<T> GimmehTehFilez(Predicate<T> match)
   {
      if (match == null)
         throw new ExceptionWTF("match", "WTF? match iz null");

      LOList<T> list = new LOList<T>();

      for (int i = 0; i < Count; ++i)
         if (match(this[i]))
            list.Add(this[i]);

      return list;
   }

   public void GTFO(Predicate<T> predicate)
   {
      if (predicate == null)
         throw new ExceptionWTF("predicate", "WTF? srlsy");

      for (int i = 0; i < Count; ++i)
         if (predicate(this[i]))
         {
            RemoveAt(i);
            break;
         }
      }

   public void FurEach(Action<T> action)
   {
      if (action == null)
         throw new ExceptionWTF("action", "LOL @ null action");

      for (int i = 0; i < Count; ++i)
         action(this[i]);
   }

I can't really sugarcoat this post by saying it is useful in any way, shape, or form.  All I did was rewrite the exact functionality that is already there with a differnet meme'ish name. I can say, however, that it could show you how to let .NET do 90% of the heavy-lifting when extending functionality to existing objects / controls or that I used Reflector (which is REALLY great if you have less-than-ideal documentation for a utility and you want to know it's capabilities).

More serious posts in the future. Swear.

ps. I created an ExceptionWTF class if you didn't already notice.

C#, Humor

kick it on DotNetKicks.com

Leave a Comment

   

  Enter the text to proceed!