Skip to content

Instantly share code, notes, and snippets.

@arjancornelissen
Created January 10, 2016 16:13
Show Gist options
  • Save arjancornelissen/e25ee7a3d1d28b73649e to your computer and use it in GitHub Desktop.
Save arjancornelissen/e25ee7a3d1d28b73649e to your computer and use it in GitHub Desktop.
Content type with Managed Metadata Feature receiver03
/// <summary>
/// Extension to search for a groupName
/// </summary>
public static class GroupExtension
{
/// <summary>
/// Search for the Group by its name
/// </summary>
/// <param name="groupCollection">The group collection to search in</param>
/// <param name="name">The name to search for</param>
/// <returns>The <see cref="Group"/> if it's found</returns>
public static Group GetByName(this GroupCollection groupCollection, string name)
{
if (String.IsNullOrEmpty(name))
{
throw new ArgumentException("Not a valid group name", "name");
}
foreach (var group in groupCollection)
{
if (group.Name == name)
{
return group;
}
}
throw new ArgumentOutOfRangeException("name", name, "Could not find the group");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment