public static PermissionCollection GetPermissions(this SecurableObject secObj) { Type secType = secObj.GetType(); string name = secType.Name.Equals("ListItem") ? "DisplayName" : "Title"; secObj.Context.Load(secObj, s => s.HasUniqueRoleAssignments, s => s.RoleAssignments); try { secObj.Context.ExecuteQuery(); } catch (ServerException) { return(null); } bool?check = secObj.IsPropertyAvailable("HasUniqueRoleAssignments") ? (bool?)secObj.HasUniqueRoleAssignments : null; if (!check.HasValue) { return(null); } //if (!(secObj is Web)) //{ // MethodInfo genMeth = typeof(ClientObjectExtensions) // .GetMethod("GetClientObjectExpression", BindingFlags.Static | BindingFlags.NonPublic) // .MakeGenericMethod(secType); // object nameExpression = genMeth.Invoke(null, new object[] // { // secObj, name // }); // object idExpression = genMeth.Invoke(null, new object[] // { // secObj, "Id" // }); // MethodInfo genLoad = typeof(ClientObjectExtensions) // .GetMethod("SpecialLoad", BindingFlags.NonPublic | BindingFlags.Static) // .MakeGenericMethod(secType); // genLoad.Invoke(secObj, new object[] // { // secObj, nameExpression // }); // genLoad.Invoke(secObj, new object[] // { // secObj, idExpression // }); // secObj.Context.ExecuteQuery(); //} PermissionCollection permissions = PermissionCollection.ResolvePermissions(secObj); //ValueTuple<string, object> tuple = GetNameAndIdValue(secObj, name); return(permissions); }
private static ValueTuple <string, object> GetNameAndIdValue(SecurableObject secObj, string nameProperty) { Type objType = secObj.GetType(); PropertyInfo namePi = objType.GetProperty(nameProperty, BindingFlags.Instance | BindingFlags.Public); PropertyInfo idPi = objType.GetProperty("Id", BindingFlags.Instance | BindingFlags.Public); string nameVal = namePi.GetValue(secObj) as string; object idVal = idPi.GetValue(secObj); return(new ValueTuple <string, object>(nameVal, idVal)); }
protected Web ExtractWeb(SecurableObject securableObject) { if (securableObject is Web) return securableObject as Web; if (securableObject is List) return (securableObject as List).ParentWeb; if (securableObject is ListItem) return (securableObject as ListItem).ParentList.ParentWeb; throw new Exception(string.Format("Can't extract SPWeb for securableObject of type: [{0}]", securableObject.GetType())); }
protected Web GetWebFromSPSecurableObject(SecurableObject securableObject) { if (securableObject is Web) { return(securableObject as Web); } if (securableObject is List) { return((securableObject as List).ParentWeb); } if (securableObject is ListItem) { return((securableObject as ListItem).ParentList.ParentWeb); } throw new Exception(string.Format("Can't extract SPWeb for securableObject of type: [{0}]", securableObject.GetType())); }