Daniel Vaughan

free range code

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




Windows Phone Experts Windows Phone Experts
LinkedIn Group

 

About the author

Daniel VaughanDaniel Vaughan is a Microsoft MVP for Client Application Development, with a decade of commercial experience across a wide range of industries including finance, e-commerce, and multimedia. While originally from Australia and the UK, Daniel is currently based in Geneva Switzerland; consulting on Windows Phone 7, WPF, Silverlight, WCF, and WF. Daniel is a Silverlight and WPF Insider, a member of the WPF Disciples, and a CodeProject MVP. Daniel is currently writing Windows Phone 7.5 Unleashed, which is due out in early 2011. 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

 

 

Books

Order Windows Phone 7 Unleashed

RecentComments

Comment RSS

Sign in