public override bool IsSubsetOf(IPermission target) { if (target == null) { // do not use Cast - different permissions (and earlier Fx) return false :-/ return(true); } ResourcePermissionBase rpb = (target as ResourcePermissionBase); if (rpb == null) { return(false); } if (rpb.IsUnrestricted()) { return(true); } if (IsUnrestricted()) { return(rpb.IsUnrestricted()); } foreach (ResourcePermissionBaseEntry entry in _list) { if (!rpb.Exists(entry)) { return(false); } } return(true); }
public override IPermission Union(IPermission target) { ResourcePermissionBase rpb = Cast(target); if (rpb == null) { return(Copy()); } if (IsEmpty() && rpb.IsEmpty()) { return(null); } if (rpb.IsEmpty()) { return(Copy()); } if (IsEmpty()) { return(rpb.Copy()); } bool unrestricted = (IsUnrestricted() || rpb.IsUnrestricted()); ResourcePermissionBase result = CreateFromType(this.GetType(), unrestricted); // strangely unrestricted union doesn't process the elements (while intersect does) if (!unrestricted) { foreach (ResourcePermissionBaseEntry entry in _list) { result.AddPermissionAccess(entry); } foreach (ResourcePermissionBaseEntry entry in rpb._list) { // don't add twice if (!result.Exists(entry)) { result.AddPermissionAccess(entry); } } } return(result); }
public override IPermission Intersect(IPermission target) { ResourcePermissionBase rpb = Cast(target); if (rpb == null) { return(null); } bool su = this.IsUnrestricted(); bool tu = rpb.IsUnrestricted(); // if one is empty we return null (unless the other one is unrestricted) if (IsEmpty() && !tu) { return(null); } if (rpb.IsEmpty() && !su) { return(null); } ResourcePermissionBase result = CreateFromType(this.GetType(), (su && tu)); foreach (ResourcePermissionBaseEntry entry in _list) { if (tu || rpb.Exists(entry)) { result.AddPermissionAccess(entry); } } foreach (ResourcePermissionBaseEntry entry in rpb._list) { // don't add twice if ((su || this.Exists(entry)) && !result.Exists(entry)) { result.AddPermissionAccess(entry); } } return(result); }