共用方式為


StrongNameIdentityPermission.IsSubsetOf(IPermission) 方法

定義

判斷目前權限是否為指定權限的子集。

public:
 override bool IsSubsetOf(System::Security::IPermission ^ target);
public override bool IsSubsetOf (System.Security.IPermission target);
override this.IsSubsetOf : System.Security.IPermission -> bool
Public Overrides Function IsSubsetOf (target As IPermission) As Boolean

參數

target
IPermission

要測試子集關聯性的權限。 這個權限必須與目前權限屬於相同的類型。

傳回

如果目前權限是指定權限的子集,則為 true,否則為 false

例外狀況

target 參數不是 null,而且與目前權限屬於不同的類型。

範例

下列程式代碼範例顯示使用 IsSubsetOf 方法的結果,而不是如何使用 方法。 這個範例是提供給 類別之較大範例的 StrongNameIdentityPermission 一部分。 此範例的最佳用法是建置和執行整個範例,並檢視其輸出。

注意

程式代碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。

// IsSubsetOf determines whether the current permission is a subset of the specified permission.
bool IsSubsetOfDemo()
{
    bool returnValue = true;

    StrongNameIdentityPermission^ snIdPerm1;
    StrongNameIdentityPermission^ snIdPerm2;

    snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", gcnew Version("1.0.0.0"));
    snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", gcnew Version("1.0.0.0"));

    if (snIdPerm1->IsSubsetOf(snIdPerm2))
    {

        Console::WriteLine("MyCompany.MyDepartment.* is a subset " +
            "of MyCompany.MyDepartment.MyFile \n");
    }
    else
    {
        Console::WriteLine("MyCompany.MyDepartment.*" +
            " is not a subset of MyCompany.MyDepartment.MyFile \n");
    }

    return returnValue;
}
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{

    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2;

    snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
    snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));

    if (snIdPerm1.IsSubsetOf(snIdPerm2))
    {

        Console.WriteLine("MyCompany.MyDepartment.* is a subset " +
        "of MyCompany.MyDepartment.MyFile \n");
    }
    else
    {
        Console.WriteLine("MyCompany.MyDepartment.*" +
        " is not a subset of MyCompany.MyDepartment.MyFile \n");
    }

    return returnValue;
}
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Function IsSubsetOfDemo() As Boolean 
    
    Dim returnValue As Boolean = True
    
    Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
    
    snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", New Version("1.0.0.0"))
    snIdPerm2 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", New Version("1.0.0.0"))
    
    If snIdPerm1.IsSubsetOf(snIdPerm2) Then
        
        Console.WriteLine("MyCompany.MyDepartment.* is a subset " + "of MyCompany.MyDepartment.MyFile " + vbLf)
    Else
        Console.WriteLine("MyCompany.MyDepartment.*" + " is not a subset of MyCompany.MyDepartment.MyFile " + vbLf)
    End If
    
    Return returnValue

End Function 'IsSubsetOfDemo

備註

如果目前的許可權指定一組完全由指定許可權所包含的作業,則目前許可權是指定許可權的子集。 例如,其他屬性相等,具有 Name 包含通配符表達式 MyCompany.MyDepartment.* 之屬性的身分識別會識別為具有 Name MyCompany.MyDepartment.MyFile 屬性之身分識別的子集。

適用於