CodeAccessPermission.Intersect(IPermission) 方法

定义

通过派生类实现时,创建和返回是当前权限和指定权限的交集的权限。

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

参数

target
IPermission

要与当前权限相交的权限。 它必须与当前权限属于同一类型。

返回

表示当前权限和指定权限的交集的一个新权限。 如果交集为空,则此新权限为 null

实现

例外

target 参数不为 null,并且是与当前权限不属于同一类的实例。

示例

下面的代码示例演示 方法的 Intersect 替代。 此代码示例是为 CodeAccessPermission 类提供的一个更大示例的一部分。

public:
   virtual IPermission^ Intersect( IPermission^ target ) override
   {
      Console::WriteLine( "************* Entering Intersect *********************" );
      if ( target == nullptr )
      {
         return nullptr;
      }

#if ( debug ) 
      Console::WriteLine( "This is = {0}", ((NameIdPermission)this).Name );
      Console::WriteLine( "Target is {0}", ((NameIdPermission)target).m_Name );
#endif 

      if (  !VerifyType( target ) )
      {
         throw gcnew ArgumentException( String::Format( "Argument is wrong type.", this->GetType()->FullName ) );
      }

      NameIdPermission^ operand = dynamic_cast<NameIdPermission^>(target);

      if ( operand->IsSubsetOf( this ) )
      {
         return operand->Copy();
      }
      else if ( this->IsSubsetOf( operand ) )
      {
         return this->Copy();
      }
      else
      {
         return nullptr;
      }
   }
        public override IPermission Intersect(IPermission target)
        {
            Console.WriteLine ("************* Entering Intersect *********************");
            if (target == null)
            {
                return null;
            }
#if(debug)
            Console.WriteLine ("This is = " + (( NameIdPermission)this).Name);
            Console.WriteLine ("Target is " + (( NameIdPermission)target).m_Name);
#endif
            if (!VerifyType(target))
            {
                throw new ArgumentException (String.Format ("Argument is wrong type.", this.GetType ().FullName));
            }

             NameIdPermission operand = ( NameIdPermission)target;

            if (operand.IsSubsetOf (this)) return operand.Copy ();
            else if (this.IsSubsetOf (operand)) return this.Copy ();
            else
                return null;
        }
        Public Overrides Function Intersect(ByVal target As IPermission) As IPermission
            Console.WriteLine("************* Entering Intersect *********************")
            If target Is Nothing Then
                Return Nothing
            End If
#If (Debug) Then

            Console.WriteLine(("This is = " + CType(Me, NameIdPermission).Name))
            Console.WriteLine(("Target is " + CType(target, NameIdPermission).m_name))
#End If
            If Not VerifyType(target) Then
                Throw New ArgumentException(String.Format("Argument is wrong type.", Me.GetType().FullName))
            End If

            Dim operand As NameIdPermission = CType(target, NameIdPermission)

            If operand.IsSubsetOf(Me) Then
                Return operand.Copy()
            ElseIf Me.IsSubsetOf(operand) Then
                Return Me.Copy()
            Else
                Return Nothing
            End If
        End Function 'Intersect

注解

两个权限的交集是一个权限,用于描述它们共同描述的操作集。 只有传递两个原始权限的要求才会传递交集。

实施者说明

必须在派生类中重写此方法。

适用于