//<snippet2> // Return a new object that contains the intersection of 'this' and 'target'. public override IPermission Intersect(IPermission target) { // If 'target' is null, return null. if (target == null) { return(null); } // Both objects must be the same type. SoundPermission soundPerm = VerifyTypeMatch(target); // If 'this' and 'target' are unrestricted, return a new unrestricted permission. if (m_specifiedAsUnrestricted && soundPerm.m_specifiedAsUnrestricted) { return(Clone(true, SoundPermissionState.PlayAnySound)); } // Calculate the intersected permissions. If there are none, return null. SoundPermissionState val = (SoundPermissionState) Math.Min((Int32)m_flags, (Int32)soundPerm.m_flags); if (val == 0) { return(null); } // Return a new object with the intersected permission value. return(Clone(false, val)); }
//</snippet5> #endregion #region ISecurityEncodable Members //<snippet6> // Populate the permission's fields from XML. public override void FromXml(SecurityElement e) { m_specifiedAsUnrestricted = false; m_flags = 0; // If XML indicates an unrestricted permission, make this permission unrestricted. String s = (String)e.Attributes["Unrestricted"]; if (s != null) { m_specifiedAsUnrestricted = Convert.ToBoolean(s); if (m_specifiedAsUnrestricted) { m_flags = SoundPermissionState.PlayAnySound; } } // If XML indicates a restricted permission, parse the flags. if (!m_specifiedAsUnrestricted) { s = (String)e.Attributes["Flags"]; if (s != null) { m_flags = (SoundPermissionState) Convert.ToInt32(Enum.Parse(typeof(SoundPermission), s, true)); } } }
// This is the Private Clone helper method. private SoundPermission Clone(Boolean specifiedAsUnrestricted, SoundPermissionState flags) { SoundPermission soundPerm = (SoundPermission)Clone(); soundPerm.m_specifiedAsUnrestricted = specifiedAsUnrestricted; soundPerm.m_flags = specifiedAsUnrestricted ? SoundPermissionState.PlayAnySound : m_flags; return(soundPerm); }
// This constructor creates and initializes a permission with specific access. public SoundPermission(SoundPermissionState flags) { if (!Enum.IsDefined(typeof(SoundPermissionState), flags)) { throw new ArgumentException ("flags value is not valid for the SoundPermissionState enuemrated type"); } m_specifiedAsUnrestricted = false; m_flags = flags; }