SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a SharePoint application, and am trying some new things to create what amounts to an API for Data Access to maintain consistency and conventions.

I haven't seen this before, and that makes me think it might be bad :)

I've overloaded the constructor for class Post to only take an SPListItem as a parameter. I then have an embedded Generic List of Post that takes an SPListItemCollection in the method signature.

I loop through the items in a more efficient for statement, and this means if I ever need to add or modify how the Post object is cast, I can do it in the Class definition for a single source.

class Post
    public int ID { get; set; }
    public string Title { get; set; }

    public Post(SPListItem item)
        ID = item.ID;
        Title = (string)item["Title"];
    public static List<Post> Posts(SPListItemCollection _items)
        var returnlist = new List<Post>();
        for (int i = 0; i < _items.Count; i++) {returnlist.Add(new Post(_items[i]));}
        return returnlist;

This enables me to do the following:

    static public List<Post> GetPostsByCommunity(string communityName) 
        var targetList = CoreLists.SystemAccount.Posts(); //CAML emitted for brevity
        return Post.Posts(targetList.GetItems(query)); //Call the constructor

Is this a bad idea?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.