Creating collection with no code (almost)

Posted by Sean Feldman on ASP.net Weblogs See other posts from ASP.net Weblogs or by Sean Feldman
Published on Sat, 15 Jan 2011 05:56:00 GMT Indexed on 2011/01/15 6:54 UTC
Read the original article Hit count: 295

Filed under:

When doing testing, I tend to create an object mother for the items generated multiple times for specifications. Quite often these objects need to be a part of a collection. A neat way to do so is to leverage .NET params mechanism:

    public static IEnumerable<T> CreateCollection<T>(params T[] items)
    {
      return items;
    }

And usage is the following:

private static IEnumerable<IPAddress> addresses = CreateCollection(new IPAddress(123456789), new IPAddress(987654321));

© ASP.net Weblogs or respective owner

Related posts about c#