I'm using the SharePoint 2007 object model API to assign a role to a SharePoint object, however when you do this, you must know the type of SharePoint object beforehand, like this:
// apply the new roleassignment to the folder. You can do this at the listitem level if desired (i.e. this could be SPfile.Item…. instead of SPFolder.Item)
folder.Item.RoleAssignments.Add(roleAssignment);
(code snippet from http://blogs.msdn.com/b/robgruen/archive/2007/11/15/how-to-programmatically-set-permissions-on-files-folders-in-a-sharepoint-document-library.aspx)
I'd like the implementation of a method that is able to pass the SharePoint object, determine the type of SharePoint object to look like this:
public static bool AssignRole(string spWebUrl, object spObject, SPUser oUser, string spRoleDefinition);
Example SharePoint object types would be: SPSite, SPWeb, SPList, SPListItem, SPField, SPFolder
Any help on how to tackle the issue of determining the type of the SharePoint object would be much appreciated.
Sidenote:
There is a way to determine the object type (sort of), if you know the full url of where the object lies in the site, although that's really not a route I'd like to go down.