共用方式為


NetworkInformationPermission.Intersect(IPermission) 方法

定義

建立並傳回目前權限與指定權限交集的權限。

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

參數

target
IPermission

與目前使用權限交集的 IPermission。 必須與目前權限屬於相同的類型。

傳回

NetworkInformationPermission,表示目前使用權限和指定之使用權限的交集。 如果交集是空的,或 targetnull,則這個新使用權限便為 null

例外狀況

範例

下列範例會建立許可權物件,該對像是現有許可權物件的交集。

System::Net::NetworkInformation::NetworkInformationPermission^ unrestricted = gcnew System::Net::NetworkInformation::NetworkInformationPermission( System::Security::Permissions::PermissionState::Unrestricted );

Console::WriteLine( L"Is unrestricted? {0}", unrestricted->IsUnrestricted() );

System::Net::NetworkInformation::NetworkInformationPermission^ read = gcnew System::Net::NetworkInformation::NetworkInformationPermission( System::Net::NetworkInformation::NetworkInformationAccess::Read );

System::Net::NetworkInformation::NetworkInformationPermission^ copyPermission = dynamic_cast<System::Net::NetworkInformation::NetworkInformationPermission^>(read->Copy());

System::Net::NetworkInformation::NetworkInformationPermission^ unionPermission = dynamic_cast<System::Net::NetworkInformation::NetworkInformationPermission^>(read->Union( unrestricted ));
Console::WriteLine( L"Is subset?{0}", read->IsSubsetOf( unionPermission ) );

System::Net::NetworkInformation::NetworkInformationPermission^ intersectPermission = dynamic_cast<System::Net::NetworkInformation::NetworkInformationPermission^>(read->Intersect( unrestricted ));
System.Net.NetworkInformation.NetworkInformationPermission unrestricted =
    new System.Net.NetworkInformation.NetworkInformationPermission(
        System.Security.Permissions.PermissionState.Unrestricted);

Console.WriteLine("Is unrestricted? " + unrestricted.IsUnrestricted());

System.Net.NetworkInformation.NetworkInformationPermission read =
    new System.Net.NetworkInformation.NetworkInformationPermission(
        System.Net.NetworkInformation.NetworkInformationAccess.Read);
System.Net.NetworkInformation.NetworkInformationPermission copyPermission =
   (System.Net.NetworkInformation.NetworkInformationPermission) read.Copy();
System.Net.NetworkInformation.NetworkInformationPermission unionPermission =
   (System.Net.NetworkInformation.NetworkInformationPermission) read.Union(unrestricted);
Console.WriteLine("Is subset?" + read.IsSubsetOf(unionPermission));
System.Net.NetworkInformation.NetworkInformationPermission intersectPermission =
   (System.Net.NetworkInformation.NetworkInformationPermission) read.Intersect(unrestricted);
Dim unrestricted As New System.Net.NetworkInformation.NetworkInformationPermission( _
    System.Security.Permissions.PermissionState.Unrestricted)
Console.WriteLine("Is unrestricted? " + unrestricted.IsUnrestricted().ToString())
Dim read As New System.Net.NetworkInformation.NetworkInformationPermission( _ 
    System.Net.NetworkInformation.NetworkInformationAccess.Read)
Dim copyPermission As System.Net.NetworkInformation.NetworkInformationPermission = _
    CType(read.Copy(), System.Net.NetworkInformation.NetworkInformationPermission)
Dim unionPermission As System.Net.NetworkInformation.NetworkInformationPermission = _
    CType(read.Union(unrestricted), System.Net.NetworkInformation.NetworkInformationPermission)
Console.WriteLine("Is subset?" + read.IsSubsetOf(unionPermission).ToString())
Dim intersectPermission As System.Net.NetworkInformation.NetworkInformationPermission = _ 
    CType(read.Intersect(unrestricted), _ 
          System.Net.NetworkInformation.NetworkInformationPermission)

備註

兩個許可權的交集是描述兩者共同描述狀態的許可權。 只有傳遞兩個原始許可權的要求才會通過交集。

適用於