NetworkInformationPermission.IsSubsetOf(IPermission) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷目前權限是否為指定權限的子集。
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
要測試其子集關聯性 (Relationship) 的 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,則目前的許可權代表對受保護資源的存取權不會超過指定的許可權。