Refactor Code

  • Gravatar
    Convert IEnumerable to EntitySet Using Extension Methods

    by azamsharp on 5/31/2008 4:20:40 PM
  • I had a requirement to convert IEnumerable to EntitySet. Although this can be accomplished in many different ways I took the Extension Method route. Here is the implementation.
  • // convert IEnumerable to an EntitySet
    public static EntitySet<T> ToEntitySet<T>(this IEnumerable<T> e) where T : class
    {
    if (e == null || e.Count() == 0)
    throw new ArgumentException("List null or does not contains any elements");

    EntitySet<T> set = new EntitySet<T>();
    set.AddRange(e);
    return set;
    }
  • Refactor it!
Please log in to refactor the code! Login