On my current project I have been using a lot of extension methods to hide things I don't like about the SharePoint API. For one I hate that the only way to determine if something is in a list, web, or group is by trying to access the item and then catch the exception. Yuck. Here is an extension method I wrote to test if a group exists in a site or not.
public
static
bool Contains(this
SPGroupCollection groups, string groupName)
{
try
{
SPGroup group = groups[groupName];
return
true;
}
catch (Exception)
{
return
false;
}
}
And here is how I use the extension method.
if (!committeesRootWeb.SiteGroups.Contains(groupName))
{
committeesRootWeb.SiteGroups.Add(groupName, member, user, groupName);
}
For a little more info check out this post:
http://johnholliday.net/post/2008/10/22/Streamline-Your-SharePoint-Code-Using-Extension-Methods.aspx