NetworkInformationPermission.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

IPermission,将对其进行测试以确定子集关系。 此权限必须与当前权限属于同一类型。

返回

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

示例

下面的代码示例显示两个权限之间的子集关系。

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 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));
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())

注解

如果当前权限指定由指定权限完全包含的状态,则当前权限是指定权限的子集。 如果此方法返回 true,则当前权限表示对受保护资源的访问权限不会超过指定权限。

适用于