internal bool IsSubsetOfHelper(PermissionSet target, IsSubsetOfType type, out IPermission firstPermThatFailed, bool ignoreNonCas) { #if _DEBUG if (debug) DEBUG_WRITE("IsSubsetOf\n" + "Other:\n" + (target == null ? "<null>" : target.ToString()) + "\nMe:\n" + ToString()); #endif firstPermThatFailed = null; if (target == null || target.FastIsEmpty()) { if(this.IsEmpty()) return true; else { firstPermThatFailed = GetFirstPerm(); return false; } } else if (this.IsUnrestricted() && !target.IsUnrestricted()) return false; else if (this.m_permSet == null) return true; else { target.CheckSet(); for (int i = m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); ++i) { IPermission thisPerm = this.GetPermission(i); if (thisPerm == null || thisPerm.IsSubsetOf(null)) continue; IPermission targetPerm = target.GetPermission(i); #if _DEBUG PermissionToken token = (PermissionToken)PermissionToken.s_tokenSet.GetItem( i ); Contract.Assert(targetPerm == null || (token.m_type & PermissionTokenType.DontKnow) == 0, "Token not properly initialized"); #endif if (target.m_Unrestricted) continue; // targetPerm can be null here, but that is fine since it thisPerm is a subset // of empty/null then we can continue in the loop. CodeAccessPermission cap = thisPerm as CodeAccessPermission; if(cap == null) { if (!ignoreNonCas && !thisPerm.IsSubsetOf( targetPerm )) { firstPermThatFailed = thisPerm; return false; } } else { firstPermThatFailed = thisPerm; switch(type) { case IsSubsetOfType.Normal: if (!thisPerm.IsSubsetOf( targetPerm )) return false; break; case IsSubsetOfType.CheckDemand: if (!cap.CheckDemand( (CodeAccessPermission)targetPerm )) return false; break; case IsSubsetOfType.CheckPermitOnly: if (!cap.CheckPermitOnly( (CodeAccessPermission)targetPerm )) return false; break; case IsSubsetOfType.CheckAssertion: if (!cap.CheckAssert( (CodeAccessPermission)targetPerm )) return false; break; } firstPermThatFailed = null; } } } return true; }
internal bool IsSubsetOfHelper(PermissionSet target, IsSubsetOfType type, out IPermission firstPermThatFailed, bool ignoreNonCas) { firstPermThatFailed = null; if ((target == null) || target.FastIsEmpty()) { if (this.IsEmpty()) { return true; } firstPermThatFailed = this.GetFirstPerm(); return false; } if (this.IsUnrestricted() && !target.IsUnrestricted()) { return false; } if (this.m_permSet != null) { target.CheckSet(); for (int i = this.m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); i++) { IPermission permission = this.GetPermission(i); if ((permission != null) && !permission.IsSubsetOf(null)) { IPermission permission2 = target.GetPermission(i); if (!target.m_Unrestricted) { CodeAccessPermission permission3 = permission as CodeAccessPermission; if (permission3 == null) { if (!ignoreNonCas && !permission.IsSubsetOf(permission2)) { firstPermThatFailed = permission; return false; } continue; } firstPermThatFailed = permission; switch (type) { case IsSubsetOfType.Normal: if (permission.IsSubsetOf(permission2)) { break; } return false; case IsSubsetOfType.CheckDemand: if (permission3.CheckDemand((CodeAccessPermission) permission2)) { break; } return false; case IsSubsetOfType.CheckPermitOnly: if (permission3.CheckPermitOnly((CodeAccessPermission) permission2)) { break; } return false; case IsSubsetOfType.CheckAssertion: if (permission3.CheckAssert((CodeAccessPermission) permission2)) { break; } return false; } firstPermThatFailed = null; } } } } return true; }