Daniel Vaughan

.NET Adventures

Scored a Triple!

clock April 26, 2010 17:01 by author Daniel Vaughan

Seems I've done rather well this month in the CodeProject article competions. With two articles I managed to take out three awards. I'm chuffed!

So, ok, now I get to gloat a bit. ;)

I won the Best C# and Best Overall article categories with this article.

And I won the Best VB.NET article category with this article.

Kudos goes out to my usual nemesis and, at the same time, good friend Sacha Barber. Sacha's awesome Bread Crumb control could have won it. Likewise Colin's innovative Linq to Tree article was tops. See Sacha's TimeLineControl for a simply superb piece of work. I forsee it being a definite winner for April's comp.

Thanks also go out to all those who supported me!



IEnumerable IsNullOrEmpty

clock April 18, 2010 15:39 by author Daniel Vaughan

String.IsNullOrEmpty is a commonly used method for determining whether a string is null or has a zero length. But, no such method exists in the FCL for collections. A moment ago I whipped up an extension method for IEnumerable types. It's not rocket science, but I thought I would post it anyway.

public static class Extensions
{
    /// <summary>
    /// Determines whether the collection is null or contains no elements.
    /// </summary>
    /// <typeparam name="T">The IEnumerable type.</typeparam>
    /// <param name="enumerable">The enumerable, which may be null or empty.</param>
    /// <returns>
    ///     <c>true</c> if the IEnumerable is null or empty; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
    {
        if (enumerable == null)
        {
            return true;
        }
        /* If this is a list, use the Count property. 
         * The Count property is O(1) while IEnumerable.Count() is O(N). */
        var collection = enumerable as ICollection<T>;
        if (collection != null)
        {
            return collection.Count < 1;
        }
        return enumerable.Any();
    }

    /// <summary>
    /// Determines whether the collection is null or contains no elements.
    /// </summary>
    /// <typeparam name="T">The IEnumerable type.</typeparam>
    /// <param name="collection">The collection, which may be null or empty.</param>
    /// <returns>
    ///     <c>true</c> if the IEnumerable is null or empty; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
    {
        if (collection == null)
        {
            return true;
        }
        return collection.Count < 1;
    }
}

 

IEnumerable.Count is O(N), while List.Count is O(1), hence the test for the IList type.



Microsoft MVP Award

clock April 3, 2010 18:24 by author Daniel Vaughan

I arrived back in Geneva on Thursday night, after spending a couple of days in Belgium attending Techdays 10. I had a blast, and some of the highlights for me were:

  • The presentation by my good friend Laurent Bugnion entitled A day in the life of a WPF/SL. Very cool.
  • I had the opportunity to ask Anders Hejlsberg about the new .NET 4.0 default parameter feature.
  • I attended a presentation on Moles. Looking forward to using that. One can replace any .NET property or method with a delegate!
  • Scott Hanselman’s keynote on day two was just so entertaining. Loved it.

All in all, it was a terrific event.

To top it all off, I discovered my MVP award from Microsoft waiting for me when I arrived home! MVP profile



About the author

Daniel VaughanDaniel Vaughan is a software developer with a decade of commercial experience across a wide range of industries including e-commerce, multimedia, and finance. While originally from Australia and the UK, Daniel is currently based in Geneva Switzerland; working with WPF, WCF, and WF within the finance industry. In his spare time Daniel likes to spend time concocting novel ideas, such as employing neural networks to predict user navigation behaviour in WPF applications, and a grid computing framework for Silverlight. Daniel is also the creator of a number of open-source projects including Calcium, and Clog. E-mail me Send mail

 

Microsoft MVP logo Disciple
CodeProject MVP
WPF and Silverlight Insiders

 

 

RecentComments

Comment RSS

Sign in