現在のアクセス許可が、指定したアクセス許可のサブセットかどうかを判断します。
Overrides Public Function IsSubsetOf( _
ByVal target As IPermission _) As Boolean Implements IPermission.IsSubsetOf
[C#]
public override bool IsSubsetOf(IPermissiontarget);
[C++]
public: bool IsSubsetOf(IPermission* target);
[JScript]
public override function IsSubsetOf(
target : IPermission) : Boolean;
パラメータ
- target
サブセットの関係を調べる対象のアクセス許可。このアクセス許可は、現在のアクセス許可と同じ型である必要があります。
戻り値
現在のアクセス許可が、指定したアクセス許可のサブセットである場合は true 。それ以外の場合は false 。
実装
例外
例外の種類 | 条件 |
---|---|
ArgumentException | target パラメータが null 参照 (Visual Basic では Nothing) ではなく、現在のアクセス許可と同じ型でもありません。 |
解説
現在のアクセス許可で指定される操作の集合が、指定したアクセス許可に完全に含まれる場合、現在のアクセス許可オブジェクトは指定したアクセス許可オブジェクトのサブセットです。たとえば、他のプロパティが等しい場合、ワイルドカード式 MyCompany.MyDepartment.* を含む Name プロパティの ID は、 Name プロパティ MyCompany.MyDepartment.MyFile の ID のサブセットとして識別されます。
使用例
[Visual Basic, C#, C++] 次に示すのは、 IsSubsetOf メソッドを使用した場合の結果を示す例です (メソッドの使用方法を示すものではありません)。よりよく理解するためには、コード全体を記述して実行し、その出力を確認することをお勧めします。ここに示すコードは、より長いコードの一部です。完全なコードについては、 StrongNameIdentityPermission クラスを参照してください。
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Function IsSubsetOfDemo() As Boolean
Dim returnValue As Boolean = True
Dim Sn1, Sn2 As String
Dim SnIdPerm1, SnIdPerm2 As StrongNameIdentityPermission
Dim SnGen1 As New SnGenerator()
Dim SnGen2 As New SnGenerator()
SnGen1.ResetIndex()
While SnGen1.CreateSn(SnIdPerm1, Sn1)
If SnIdPerm1 Is Nothing Then
GoTo ContinueWhile1
End If
Console.WriteLine("**********************************************************" + ControlChars.Lf)
SnGen2.ResetIndex()
While SnGen2.CreateSn(SnIdPerm2, Sn2)
Dim firstPermission As String = IIf(Sn1 = "" Or Sn1 Is Nothing, "null", Sn1)
Dim secondPermission As String = IIf(Sn2 = "" Or Sn2 Is Nothing, "null", Sn2)
If SnIdPerm2 Is Nothing Then
GoTo ContinueWhile2
End If
Try
If SnIdPerm1.IsSubsetOf(SnIdPerm2) Then
Console.WriteLine((firstPermission _
+ IIf(firstPermission.Length < 10, " ", ControlChars.Lf + ControlChars.Tab) _
+ " is a subset of " + secondPermission + ControlChars.Lf))
Else
Console.WriteLine((firstPermission _
+ IIf(firstPermission.Length < 10, " ", ControlChars.Lf + ControlChars.Tab) _
+ " is not a subset of " + secondPermission + ControlChars.Lf))
End If
Catch e As Exception
Console.WriteLine(IIf("An exception was thrown for subset :" + Sn1 = "", "null", IIf(Sn1 + ControlChars.Lf + Sn2 = "", "null", Sn2 + ControlChars.Lf + e.ToString())))
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'IsSubsetOfDemo
[C#]
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{
bool returnValue = true;
string sn1,sn2;
StrongNameIdentityPermission snIdPerm1,snIdPerm2;
SnGenerator snGen1 = new SnGenerator();
SnGenerator snGen2 = new SnGenerator();
snGen1.ResetIndex();
while(snGen1.CreateSn(out snIdPerm1, out sn1))
{
if(snIdPerm1 == null) continue;
Console.WriteLine("**********************************************************\n");
snGen2.ResetIndex();
while(snGen2.CreateSn(out snIdPerm2, out sn2))
{
string firstPermission = sn1 == "" | sn1 == null ? "null" : sn1 ;
string secondPermission = sn2 == "" | sn2 == null ? "null" : sn2;
if(snIdPerm2 == null) continue;
try
{
if (snIdPerm1.IsSubsetOf(snIdPerm2))
{
Console.WriteLine(firstPermission + ((firstPermission.Length < 10) ? " " : "\n\t") +
" is a subset of " + secondPermission + "\n");
}
else
{
Console.WriteLine(firstPermission + ((firstPermission.Length < 10) ? " " : "\n\t") +
" is not a subset of " + secondPermission + "\n");
}
}
catch(Exception e)
{
Console.WriteLine("An exception was thrown for subset :" +
sn1 == "" ? "null" : sn1 + "\n" + sn2 == "" ? "null" : sn2 +"\n" + e);
}
}
}
return returnValue;
}
[C++]
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
bool IsSubsetOfDemo() {
bool returnValue = true;
String* sn1, *sn2;
StrongNameIdentityPermission* snIdPerm1, *snIdPerm2;
SnGenerator* snGen1 = new SnGenerator();
SnGenerator* snGen2 = new SnGenerator();
snGen1->ResetIndex();
while(snGen1->CreateSn(&snIdPerm1, &sn1)) {
if (snIdPerm1 == 0) continue;
Console::WriteLine(S"**********************************************************\n");
snGen2->ResetIndex();
while(snGen2->CreateSn(&snIdPerm2, &sn2)) {
String* firstPermission = sn1->Equals(S"") || sn1 == 0 ? S"null" : sn1 ;
String* secondPermission = sn2->Equals(S"") || sn2 == 0 ? S"null" : sn2;
if (snIdPerm2 == 0) continue;
try {
if (snIdPerm1->IsSubsetOf(snIdPerm2)) {
Console::WriteLine(S"{0}{1} is a subset of {2}\n", firstPermission,
((firstPermission->Length < 10) ? S" " : S"\n\t"),
secondPermission);
} else {
Console::WriteLine(S"{0}{1} is not a subset of {2}\n", firstPermission,
((firstPermission->Length < 10) ? S" " : S"\n\t"),
secondPermission);
}
} catch (Exception* e) {
Console::WriteLine(S"An exception was thrown for subset : {0}\n{1}\n{2}",
sn1->Equals(S"") ? S"null" : sn1,
sn2->Equals(S"") ? S"null" : sn2, e);
}
}
}
return returnValue;
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
StrongNameIdentityPermission クラス | StrongNameIdentityPermission メンバ | System.Security.Permissions 名前空間