IPermission.Intersect(IPermission) メソッド

定義

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

public:
 System::Security::IPermission ^ Intersect(System::Security::IPermission ^ target);
public System.Security.IPermission Intersect (System.Security.IPermission target);
public System.Security.IPermission? Intersect (System.Security.IPermission? target);
abstract member Intersect : System.Security.IPermission -> System.Security.IPermission
Public Function Intersect (target As IPermission) As IPermission

パラメーター

target
IPermission

現在のアクセス許可との共通部分のあるアクセス許可。 これは、現在のアクセス許可と同じ型であることが必要です。

戻り値

IPermission

現在のアクセス許可と指定したアクセス許可の共通部分を表す新しいアクセス許可。 積集合が空の場合、この新しいアクセス許可は null です。

例外

target パラメーターは null ではなく、現在のアクセス許可と同じクラスのインスタンスでもありません。

次のコード例は、メソッドの実装を Intersect 示しています。 このコード例は、IPermission クラスのために提供されている大規模な例の一部です。

    // Return a new object that contains the intersection 
    // of 'this' and 'target'.
public:
    virtual IPermission^ Intersect(IPermission^ target) override
    {
        // If 'target' is null, return null.
        if (target == nullptr)
        {
            return nullptr;
        }

        // Both objects must be the same type.
        SoundPermission^ soundPerm = VerifyTypeMatch(target);

        // If 'this' and 'target' are unrestricted, 
        // return a new unrestricted permission.
        if (specifiedAsUnrestricted && soundPerm->specifiedAsUnrestricted)
        {
            return Clone(true, SoundPermissionState::PlayAnySound);
        }

        // Calculate the intersected permissions. 
        // If there are none, return null.
        SoundPermissionState minimumPermission = (SoundPermissionState)
            Math::Min((int) stateFlags, (int) soundPerm->stateFlags);
        if ((int)minimumPermission == 0)
        {
            return nullptr;
        }

        // Return a new object with the intersected permission value.
        return Clone(false, minimumPermission);
    }
// Return a new object that contains the intersection of 'this' and 'target'.
public override IPermission Intersect(IPermission target)
{
    // If 'target' is null, return null.
    if (target == null) return null;

    // Both objects must be the same type.
    SoundPermission soundPerm = VerifyTypeMatch(target);

    // If 'this' and 'target' are unrestricted, return a new unrestricted permission.
    if (m_specifiedAsUnrestricted && soundPerm.m_specifiedAsUnrestricted)
        return Clone(true, SoundPermissionState.PlayAnySound);

    // Calculate the intersected permissions. If there are none, return null.
    SoundPermissionState val = (SoundPermissionState)
        Math.Min((Int32)m_flags, (Int32)soundPerm.m_flags);
    if (val == 0) return null;

    // Return a new object with the intersected permission value.
    return Clone(false, val);
}
' Return a new object that contains the intersection of 'this' and 'target'.
Public Overrides Function Intersect(ByVal target As IPermission) As IPermission
    ' If 'target' is null, return null.
    If target Is Nothing Then
        Return Nothing
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' If 'this' and 'target' are unrestricted, return a new unrestricted permission.
    If m_specifiedAsUnrestricted AndAlso soundPerm.m_specifiedAsUnrestricted Then
        Return Clone(True, SoundPermissionState.PlayAnySound)
    End If
    ' Calculate the intersected permissions. If there are none, return null.
    Dim val As SoundPermissionState = CType(Math.Min(CType(m_flags, Int32), CType(soundPerm.m_flags, Int32)), SoundPermissionState)
    If val = 0 Then
        Return Nothing
    End If
    ' Return a new object with the intersected permission value.
    Return Clone(False, val)

End Function 'Intersect

注釈

2 つのアクセス許可の積集合は、両者が共通して記述する操作のセットを記述するアクセス許可です。 両方の元のアクセス許可を渡す要求のみが交差を通過します。

次のステートメントは、メソッドのすべての実装 Intersect に対して true である必要があります。 XではないY``nullオブジェクト参照を表IPermissionします。

  • X.Intersect(X) は、次の値を X返します。

  • X.Intersect(Y) は 、 Y.Intersect(X).

  • X.Intersect(null) が返します null

適用対象