Generic properties

As part of a project I am working on, I need to create an appointment calendar with appointments that can be tagged with and one (or more) of four tag groups.  The appointment viewer can then be filtered to see only appointments tagged with selected properties.

The tags are stored in a generic pot with all of the tags, and then are themselves tagged by Type. 
(Can amyone say MetaInformation.  Yeah, there’s an app for that.)  The tags of each type should have their own checkboxlist. The UI looks like this:

 clip_image002

There are a number of ways that I could implement the collection that I bind to the listbox, but I am using Telerik controls and they would really like a generic list.  OK, I can handle that, right?  I can make a generic List of the particular POCO, and just pass it through.  But … how do I filter?  In the old days I would write a sproc, but these days, we have LINQ, and this is a job for LINQ to Objects (really the only LINQ that matters …)

protected List<Tag> Clients
{
    get
    {
        var clients = from x in Tags
                      where x.Type == "Clients"

                      select x;         return clients.ToList();
    }

}
protected List<Tag> Resources
{
    get
    {
        var resource = from x in Tags
                    where x.Type == "Resource"

                    select x;
        return resource.ToList();
    }
}
protected List<Tag> Staff
{
    get
    {
        var staff = from x in Tags
                      where x.Type == "Staff"
                      select x;
        return staff.ToList();
    }
}

protected List<Tag> TextTags {
    get
    {         var tag = from x in Tags
                    where x.Type == "Tag"
                    select x;
        return tag.ToList();
    }
}

Now I can work from the Tags collection in the entity model, and easily get just the values I need.  I can get rid of the magic values with an enumerator, but I thought it was a good use of Linq.

Comments are closed

Bill Sempf

Husband. Father. Pentester. Secure software composer. Brewer. Lockpicker. Ninja. Insurrectionist. Lumberjack. All words that have been used to describe me recently. I help people write more secure software.

PageList

profile for Bill Sempf on Stack Exchange, a network of free, community-driven Q&A sites

MonthList