To Add and Remove a Role Def:
To Add******SPRoleDefinition newRole = SharepointHelper.FindRoleDefinition(web.RoleDefinitions, "AdminPermissions");if (newRole == null) { newRole = new SPRoleDefinition(); newRole.Name = "AdminPermissions"; newRole.Description = "Can edit and approve pages, list items, and documents."; newRole.BasePermissions = SPBasePermissions.CancelCheckout | SPBasePermissions.AddListItems ; web.RoleDefinitions.Add(newRole);}To Remove**********SPRoleDefinition roleDef = SharepointHelper.FindRoleDefinition(web.RoleDefinitions, "AdminPermissions");if(roleDef!=null){ web.RoleDefinitions.Remove(roleDef);}
Utility Method
public SPRoleDefinition FindRoleDefinition(SPRoleDefinitionCollection roledefColls, string roleName) { foreach (SPRoleDefinition definition in roledefColls) { if (definition.Name.ToUpper(CultureInfo.InvariantCulture) == roleName.ToUpper(CultureInfo.InvariantCulture)) return definition; } return null; }
Using SPBasePermissions enumerations you can add your base permissions which creating a Role Def.