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 只有在 和 代表相同的許可權集時 XY ,才會) 。

  • 如果為 X 。IsSubsetOf (Y) 和 Y 。IsSubsetOf (Z) 兩者都會傳回 trueX 。IsSubsetOf () Z 會傳 true 回 。

如果 X 表示具有 許可權狀態的 None 空白 IPermission 物件,則 Y 表示 IPermissionnullX 的物件。IsSubsetOf () Y 會傳 true 回 。 如果 Z 也是空許可權,則複合集作業 X 。聯集 (Z) 。IsSubsetOf (Y) 也會傳 true 回 ,因為兩個空白許可權的聯集是空許可權。

適用於