UIPermission.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
要測試子集關聯性的權限。 這個權限必須與目前權限屬於相同的類型。
傳回
如果目前權限是指定權限的子集,則為 true
,否則為 false
。
例外狀況
target
參數不是 null
,而且與目前權限屬於不同的類型。
範例
下列程式碼範例顯示 方法的行為 IsSubsetOf 。 此範例是針對 類別提供的較大範例的 UIPermission 一部分。
注意
程式碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
void IsSubsetOfDemo()
{
Console::WriteLine("\n********************** IsSubsetOf() Demo **********************\n");
UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows);
UIPermission ^ uiPerm2 = gcnew UIPermission(UIPermissionWindow::SafeSubWindows);
Console::WriteLine(" {0} is {1}a subset of {2} ", uiPerm1->Window,
uiPerm1->IsSubsetOf(uiPerm2)?"":"not ", uiPerm2->Window);
Console::WriteLine(" {0} is {1}a subset of {2} ", uiPerm2->Window,
uiPerm2->IsSubsetOf(uiPerm1)?"":"not ", uiPerm1->Window);
uiPerm1 = gcnew UIPermission(UIPermissionClipboard::AllClipboard);
uiPerm2 = gcnew UIPermission(UIPermissionClipboard::OwnClipboard);
Console::WriteLine(" {0} is {1}a subset of {2} ", uiPerm1->Clipboard,
uiPerm1->IsSubsetOf(uiPerm2)?"":"not ", uiPerm2->Clipboard);
Console::WriteLine(" {0} is {1}a subset of {2} ", uiPerm2->Clipboard,
uiPerm2->IsSubsetOf(uiPerm1)?"":"not ", uiPerm1->Clipboard);
}
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private static void IsSubsetOfDemo()
{
UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
UIPermission uiPerm2 = new UIPermission(UIPermissionWindow.SafeSubWindows);
CheckIsSubsetOfWindow(uiPerm1, uiPerm2);
uiPerm1 = new UIPermission(UIPermissionClipboard.AllClipboard);
uiPerm2 = new UIPermission(UIPermissionClipboard.OwnClipboard);
CheckIsSubsetOfClipBoard(uiPerm1, uiPerm2);
}
private static void CheckIsSubsetOfWindow(UIPermission uiPerm1, UIPermission uiPerm2)
{
if (uiPerm1.IsSubsetOf(uiPerm2))
{
Console.WriteLine(uiPerm1.Window.ToString() + " is a subset of " +
uiPerm2.Window.ToString());
}
else
{
Console.WriteLine(uiPerm1.Window.ToString() + " is not a subset of " +
uiPerm2.Window.ToString());
}
if (uiPerm2.IsSubsetOf(uiPerm1))
{
Console.WriteLine(uiPerm2.Window.ToString() + " is a subset of " +
uiPerm1.Window.ToString());
}
else
{
Console.WriteLine(uiPerm2.Window.ToString() + " is not a subset of " +
uiPerm1.Window.ToString());
}
}
private static void CheckIsSubsetOfClipBoard(UIPermission uiPerm1, UIPermission uiPerm2)
{
if (uiPerm1.IsSubsetOf(uiPerm2))
{
Console.WriteLine(uiPerm1.Clipboard.ToString() + " is a subset of " +
uiPerm2.Clipboard.ToString());
}
else
{
Console.WriteLine(uiPerm1.Clipboard.ToString() + " is not a subset of " +
uiPerm2.Clipboard.ToString());
}
if (uiPerm2.IsSubsetOf(uiPerm1))
{
Console.WriteLine(uiPerm2.Clipboard.ToString() + " is a subset of " +
uiPerm1.Clipboard.ToString());
}
else
{
Console.WriteLine(uiPerm2.Clipboard.ToString() + " is not a subset of " +
uiPerm1.Clipboard.ToString());
}
}
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Shared Sub IsSubsetOfDemo()
Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows)
Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows)
CheckIsSubsetOfWindow(uiPerm1, uiPerm2)
uiPerm1 = New UIPermission(UIPermissionClipboard.AllClipboard)
uiPerm2 = New UIPermission(UIPermissionClipboard.OwnClipboard)
CheckIsSubsetOfClipBoard(uiPerm1, uiPerm2)
End Sub
Private Shared Sub CheckIsSubsetOfWindow(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission)
If uiPerm1.IsSubsetOf(uiPerm2) Then
Console.WriteLine(uiPerm1.Window.ToString() + " is a subset of " + uiPerm2.Window.ToString())
Else
Console.WriteLine(uiPerm1.Window.ToString() + " is not a subset of " + uiPerm2.Window.ToString())
End If
If uiPerm2.IsSubsetOf(uiPerm1) Then
Console.WriteLine(uiPerm2.Window.ToString() + " is a subset of " + uiPerm1.Window.ToString())
Else
Console.WriteLine(uiPerm2.Window.ToString() + " is not a subset of " + uiPerm1.Window.ToString())
End If
End Sub
Private Shared Sub CheckIsSubsetOfClipBoard(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission)
If uiPerm1.IsSubsetOf(uiPerm2) Then
Console.WriteLine(uiPerm1.Clipboard.ToString() + " is a subset of " + uiPerm2.Clipboard.ToString())
Else
Console.WriteLine(uiPerm1.Clipboard.ToString() + " is not a subset of " + uiPerm2.Clipboard.ToString())
End If
If uiPerm2.IsSubsetOf(uiPerm1) Then
Console.WriteLine(uiPerm2.Clipboard.ToString() + " is a subset of " + uiPerm1.Clipboard.ToString())
Else
Console.WriteLine(uiPerm2.Clipboard.ToString() + " is not a subset of " + uiPerm1.Clipboard.ToString())
End If
End Sub
備註
如果目前許可權的所有要求對目前許可權都成功,則目前的許可權是指定許可權的子集。 也就是說,指定的許可權至少包含子集中包含的許可權。 若要 IsSubsetOf 傳回 true
,目前許可權的 UIPermissionWindow 和 UIPermissionClipboard 值必須等於或小於指定許可權的值。