IPermission.IsSubsetOf(IPermission) 方法

定义

确定当前权限是否为指定权限的子集。

public:
 bool IsSubsetOf(System::Security::IPermission ^ target);
public bool IsSubsetOf (System.Security.IPermission target);
public bool IsSubsetOf (System.Security.IPermission? target);
abstract member IsSubsetOf : System.Security.IPermission -> bool
Public Function IsSubsetOf (target As IPermission) As Boolean

参数

target
IPermission

将要测试子集关系的权限。 此权限必须与当前权限属于同一类型。

返回

如果当前权限是指定权限的子集,则为 true;否则为 false

例外

target 参数不为 null,并且与当前权限不属于同一类型。

示例

下面的代码示例演示如何实现 IsSubsetOf 方法。 此代码示例是为 IPermission 类提供的一个更大示例的一部分。

    // Called by the Demand method: returns true 
    // if 'this' is a subset of 'target'.
public:
    virtual bool IsSubsetOf(IPermission^ target) override
    {
        // If 'target' is null and this permission allows nothing, 
        // return true.
        if (target == nullptr)
        {
            return (int)stateFlags == 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 stateFlags <= soundPerm->stateFlags;
    }
// 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;
}
' Called by the Demand method: returns true if 'this' is a subset of 'target'.
Public Overrides Function IsSubsetOf(ByVal target As IPermission) As [Boolean]
    ' If 'target' is null and this permission allows nothing, return true.
    If target Is Nothing Then
        Return m_flags = 0
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' Return true if the permissions of 'this' is a subset of 'target'.
    Return m_flags <= soundPerm.m_flags

End Function 'IsSubsetOf

注解

如果当前权限指定由指定权限完全包含的一组操作,则当前权限是指定权限的子集。 例如,表示C:\example.txt访问权限的权限是表示对 C:\的访问权限的子集。 如果此方法返回 true,则当前权限表示对受保护资源的访问权限不会超过指定权限。

对于 方法的所有实现 IsSubsetOf ,以下语句必须为 true。 XYZ 表示 IPermission 不是 null的对象。

  • X.IsSubsetOf (X) 返回 true

  • X.IsSubsetOf (Y) 返回与 相同的值Y。IsSubsetOf (X 当且仅当 和 Y 表示同一组权限时才X) 。

  • 如果 X为 。IsSubsetOf (Y) 和 Y。IsSubsetOf (Z) 都返回 trueX。IsSubsetOf (Z) 返回 true

如果 X 表示权限状态为 的NoneIPermission对象,并且 Y 表示为 的对象,XnullIPermission 。IsSubsetOf (Y) 返回 true。 如果 Z 也是空权限,则复合集操作 X。联合 (Z) 。IsSubsetOf (Y) 也返回 , true 因为两个空权限的并集是空权限。

适用于