次の方法で共有


RegistryPermission.Intersect メソッド

現在のアクセス許可と指定したアクセス許可の積集合を表すアクセス許可を作成して返します。

Overrides Public Function Intersect( _
   ByVal target As IPermission _) As IPermission Implements IPermission.Intersect
[C#]
public override IPermission Intersect(IPermissiontarget);
[C++]
public: IPermission* Intersect(IPermission* target);
[JScript]
public override function Intersect(
   target : IPermission) : IPermission;

パラメータ

  • target
    現在のアクセス許可との積集合を持つアクセス許可。これは、現在のアクセス許可と同じ型であることが必要です。

戻り値

現在のアクセス許可と指定したアクセス許可の積集合を表す新しいアクセス許可。積集合が空の場合、この新しいアクセス許可は null 参照 (Visual Basic では Nothing) です。

実装

IPermission.Intersect

例外

例外の種類 条件
ArgumentException target パラメータが null 参照 (Visual Basic では Nothing) ではなく、現在のアクセス許可と同じ型でもありません。

解説

2 つのアクセス許可の積集合となるアクセス許可には、両方に共通する操作の集合が記述されています。2 つのアクセス許可を要求し、その両方について要求が満たされる場合にだけ、それらの積集合を表すアクセス許可に対する要求も満たされます。

使用例

 
' Intersect creates and returns a new permission that is the intersection of the 
' current permission and the permission specified.
Private Function IntersectDemo() As Boolean

    Dim returnValue As Boolean = True

    Dim reg1, reg2 As String
    Dim regPerm1, regPerm2, regIdPerm3 As RegistryPermission

    Dim regGen1 As New regGenerator()
    Dim regGen2 As New regGenerator()

    regGen1.ResetIndex()
    While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read)
        If reg1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        regGen2.ResetIndex()

        While regGen2.CreateReg(regPerm2, reg2, RegistryPermissionAccess.Read)
            If regPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            Dim firstPermission As String = IIf(reg1 = "" Or reg1 Is Nothing, "null", reg1)
            Dim secondPermission As String = IIf(reg2 = "" Or reg2 Is Nothing, "null", reg2)
            Try

                regIdPerm3 = CType(regPerm1.Intersect(regPerm2), RegistryPermission)
                If Not (regIdPerm3 Is Nothing) AndAlso Not (regIdPerm3.GetPathList(RegistryPermissionAccess.Read) Is Nothing) Then

                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(regIdPerm3, RegistryPermission).GetPathList(RegistryPermissionAccess.Read).ToString()))
                Else
                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " is null. "))
                End If
            Catch e As Exception
                Console.WriteLine(("An exception was thrown for intersection : " & e.ToString()))
                returnValue = False
            End Try
ContinueWhile2:
        End While
ContinueWhile1:
    End While

    Return returnValue
End Function 'IntersectDemo


[C#] 
// Intersect creates and returns a new permission that is the intersection of the 
// current permission and the permission specified.
private bool IntersectDemo()
{

    bool returnValue = true;

    string reg1,reg2;
    RegistryPermission regPerm1,regPerm2,regIdPerm3;

    RegGenerator regGen1 = new RegGenerator();
    RegGenerator regGen2 = new RegGenerator();

    regGen1.ResetIndex();
    while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) 
    {
        if(reg1 == null) continue;
        Console.WriteLine("**********************************************************\n");
        regGen2.ResetIndex();

        while(regGen2.CreateReg(out regPerm2, out reg2, RegistryPermissionAccess.Read)) 
        {
            if(regPerm2 == null) continue;
            string firstPermission = reg1 == "" | reg1 == null ? "null" : reg1 ;
            string secondPermission = reg2 == "" | reg2 == null ? "null" : reg2;
            try
            {
        
                regIdPerm3 = (RegistryPermission)regPerm1.Intersect(regPerm2);
                if (regIdPerm3 != null && regIdPerm3.GetPathList(RegistryPermissionAccess.Read) != null)
                {

                    Console.WriteLine("The intersection of " + firstPermission 
                        + "  and \n\t"  + secondPermission + " = \n\t" 
                        + ((RegistryPermission)regIdPerm3).GetPathList(RegistryPermissionAccess.Read).ToString());
                }
                else
                {
                    Console.WriteLine("The intersection of " + firstPermission 
                        + "  and \n\t"  + secondPermission + " is null. ");
                }
            }
            catch(Exception e) 
            {
                Console.WriteLine("An exception was thrown for intersection : "  + e);
                returnValue=false;
            }
        }
    }

    return returnValue;

}

[C++] 
// Intersect creates and returns a new permission that is the intersection of the 
// current permission and the permission specified.
bool IntersectDemo()
{

    bool returnValue = true;

    String* reg1;
    String* reg2;
    RegistryPermission* regPerm1;
    RegistryPermission* regPerm2;
    RegistryPermission* regIdPerm3;

    RegGenerator* regGen1 = new RegGenerator();
    RegGenerator* regGen2 = new RegGenerator();

    regGen1->ResetIndex();
    while(regGen1->CreateReg(&regPerm1, &reg1, RegistryPermissionAccess::Read)) 
    {
        if(reg1 == 0) continue;
        Console::WriteLine(S"**********************************************************\n");
        regGen2->ResetIndex();

        while(regGen2->CreateReg(&regPerm2, &reg2, RegistryPermissionAccess::Read)) 
        {
            if(regPerm2 == 0) continue;
            String* firstPermission = reg1->Equals(S"") || reg1 == 0 ? S"null" : reg1 ;
            String* secondPermission = reg2->Equals(S"") || reg2 == 0 ? S"null" : reg2;
            try
            {

                regIdPerm3 = dynamic_cast<RegistryPermission*>(regPerm1->Intersect(regPerm2));
                if (regIdPerm3 != 0 && regIdPerm3->GetPathList(RegistryPermissionAccess::Read) != 0)
                {

                    Console::WriteLine(S"The intersection of {0}  and \n\t{1} = \n\t{2}", firstPermission, secondPermission, (dynamic_cast<RegistryPermission*>(regIdPerm3))->GetPathList(RegistryPermissionAccess::Read));
                }
                else
                {
                    Console::WriteLine(S"The intersection of {0}  and \n\t{1} is null. ", firstPermission, secondPermission);
                }
            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"An exception was thrown for intersection : {0}", e);
                returnValue=false;
            }
        }
    }

    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 ファミリ

参照

RegistryPermission クラス | RegistryPermission メンバ | System.Security.Permissions 名前空間