示例#1
0
    //<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));
    }
示例#2
0
    // 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);
    }
示例#3
0
    //</snippet2>

    //<snippet3>
    // Called by the Demand method: returns true if 'this' is a subset of 'target'.
    public override Boolean IsSubsetOf(IPermission target)
    {
        // If 'target' is null and this permission allows nothing, return true.
        if (target == null)
        {
            return(m_flags == 0);
        }

        // Both objects must be the same type.
        SoundPermission soundPerm = VerifyTypeMatch(target);

        // Return true if the permissions of 'this' is a subset of 'target'.
        return(m_flags <= soundPerm.m_flags);
    }
示例#4
0
    //</snippet4>

    //<snippet5>
    // Return a new object that contains the union of 'this' and 'target'.
    // Note: You do not have to implement this method. If you do not, the version
    // in CodeAccessPermission does this:
    //    1. If target is not null, a NotSupportedException is thrown.
    //    2. If target is null, then Copy is called and the new object is returned.
    public override IPermission Union(IPermission target)
    {
        // If 'target' is null, then return a copy of 'this'.
        if (target == null)
        {
            return(Copy());
        }

        // Both objects must be the same type.
        SoundPermission soundPerm = VerifyTypeMatch(target);

        // If 'this' or 'target' are unrestricted, return a new unrestricted permission.
        if (m_specifiedAsUnrestricted || soundPerm.m_specifiedAsUnrestricted)
        {
            return(Clone(true, SoundPermissionState.PlayAnySound));
        }

        // Return a new object with the calculated, unioned permission value.
        return(Clone(false, (SoundPermissionState)
                     Math.Max((Int32)m_flags, (Int32)soundPerm.m_flags)));
    }