Freigeben über


IsolatedStorageFilePermission.Copy-Methode

Erstellt eine identische Kopie der aktuellen Berechtigung und gibt die Kopie zurück.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides Function Copy As IPermission
'Usage
Dim instance As IsolatedStorageFilePermission
Dim returnValue As IPermission

returnValue = instance.Copy
public override IPermission Copy ()
public:
virtual IPermission^ Copy () override
public IPermission Copy ()
public override function Copy () : IPermission

Rückgabewert

Eine Kopie der aktuellen Berechtigung.

Hinweise

Eine Kopie einer Berechtigung stellt denselben Ressourcenzugriff dar wie die ursprüngliche Berechtigung.

Beispiel

Im folgenden Code wird die Verwendung der Copy-Methode veranschaulicht. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die IsolatedStorageFilePermission-Klasse.

Private Sub Copy_EqualsDemo()
    Console.WriteLine(ControlChars.Lf + "Copy_Equals demo.")
    Console.WriteLine("Creating the first IsolatedStorageFilePermission(PermissionState.Unrestricted) permission.")
    Dim first As New IsolatedStorageFilePermission(PermissionState.Unrestricted)
    Console.WriteLine(("Hashcode for the first permission : " + first.GetHashCode().ToString()))
    Console.WriteLine("Copying the first permission.")
    Dim copyOfFirst As IsolatedStorageFilePermission = CType(first.Copy(), IsolatedStorageFilePermission)
    Console.WriteLine(("Hashcode for copy of the first permission: " + copyOfFirst.GetHashCode().ToString()))
    If False = copyOfFirst.Equals(first) Then ' This should be false, because the object references are different.
        Console.WriteLine(("The copy and the first permission should not be equal because they have " + ControlChars.Lf + ControlChars.Tab + "different object references."))
    Else
        Console.WriteLine(("Error: the copy and the first permission should not be equal because they have " + ControlChars.Lf + ControlChars.Tab + "different object references."))
    End If

    Console.WriteLine(("Does a comparison of copy of first permission to itself test equal??: " + IIf(copyOfFirst.Equals(copyOfFirst), "true", "false")))
    If False = copyOfFirst.Equals(copyOfFirst) Then
        Console.WriteLine("Copy_Equals demo failed because Equals returns false on two object.Equals(itself).")
    End If

    Console.WriteLine(("Does a comparison of first permission to itself test equal?: " + IIf(first.Equals(first), "true", "false")))
    If False = first.Equals(first) Then
        Console.WriteLine("Copy_Equals demo failed, because Equals returns false on two object.Equals(itself).")
    End If
    Console.WriteLine("Creating a second permission with PermissionState.None.")
    Dim second As New IsolatedStorageFilePermission(PermissionState.None)

    Console.WriteLine(("Does the first permission equal the second permission?: " + IIf(first.Equals(second), "true", "false")))
    If True = first.Equals(second) Then
        Console.WriteLine("Copy_Equals demo failed because Equals returns false on two object.Equals(itself).")
    End If
End Sub 'Copy_EqualsDemo
private void Copy_EqualsDemo()
{
    Console.WriteLine
        ("\nCopy_Equals demo.");
    Console.WriteLine
        ("Creating the first IsolatedStorageFilePermission(PermissionState.Unrestricted) permission.");
    IsolatedStorageFilePermission first = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
    Console.WriteLine
        ("Hashcode for the first permission : " + first.GetHashCode().ToString());
    Console.WriteLine
        ("Copying the first permission.");
    IsolatedStorageFilePermission copyOfFirst = (IsolatedStorageFilePermission)first.Copy();
    Console.WriteLine
        ("Hashcode for copy of the first permission: " + copyOfFirst.GetHashCode().ToString());
    if (false == copyOfFirst.Equals(first)) // This should be false, because the object references are different.
    {
        Console.WriteLine
            ("The copy and the first permission should not be equal because they have " +
            "\n\tdifferent object references.");
    }
    else
    {
        Console.WriteLine
            ("Error: the copy and the first permission should not be equal because they have " +
            "\n\tdifferent object references.");
    }

    Console.WriteLine
        ("Does a comparison of copy of first permission to itself test equal??: "
        + (copyOfFirst.Equals(copyOfFirst)? "true": "false"));
    if (false == copyOfFirst.Equals(copyOfFirst))
    {
        Console.WriteLine
            ("Copy_Equals demo failed because Equals returns false on two object.Equals(itself).");
    }

    Console.WriteLine
        ("Does a comparison of first permission to itself test equal?: " + (first.Equals(first)? "true": "false"));
    if (false == first.Equals(first))
    {
        Console.WriteLine
            ("Copy_Equals demo failed, because Equals returns false on two object.Equals(itself).");
    }
    Console.WriteLine("Creating a second permission with PermissionState.None.");
    IsolatedStorageFilePermission second = new IsolatedStorageFilePermission(PermissionState.None);

    Console.WriteLine
        ("Does the first permission equal the second permission?: " + (first.Equals(second)? "true": "false"));
    if (true == first.Equals(second))
    {
        Console.WriteLine
            ("Copy_Equals demo failed because Equals returns false on two object.Equals(itself).");
    }
}
void Copy_EqualsDemo()
{
   Console::WriteLine( "\nCopy_Equals demo." );
   Console::WriteLine( "Creating the first IsolatedStorageFilePermission(PermissionState.Unrestricted) permission." );
   IsolatedStorageFilePermission^ first = gcnew IsolatedStorageFilePermission( PermissionState::Unrestricted );
   Console::WriteLine( "Hashcode for the first permission : {0}", first->GetHashCode() );
   Console::WriteLine( "Copying the first permission." );
   IsolatedStorageFilePermission^ copyOfFirst = dynamic_cast<IsolatedStorageFilePermission^>(first->Copy());
   Console::WriteLine( "Hashcode for copy of the first permission: {0}", copyOfFirst->GetHashCode() );
   if ( false == copyOfFirst->Equals( first ) )
   {
      Console::WriteLine( "The copy and the first permission should not be equal because they have "
      "\n\tdifferent object references." );
   }
   else
   {
      Console::WriteLine( "Error: the copy and the first permission should not be equal because they have "
      "\n\tdifferent object references." );
   }

   Console::WriteLine( "Does a comparison of copy of first permission to itself test equal??: {0}", (copyOfFirst->Equals( copyOfFirst ) ? (String^)"true" : "false") );
   if ( false == copyOfFirst->Equals( copyOfFirst ) )
   {
      Console::WriteLine( "Copy_Equals demo failed because Equals returns false on two object.Equals(itself)." );
   }

   Console::WriteLine( "Does a comparison of first permission to itself test equal?: {0}", (first->Equals( first ) ? (String^)"true" : "false") );
   if ( false == first->Equals( first ) )
   {
      Console::WriteLine( "Copy_Equals demo failed, because Equals returns false on two object.Equals(itself)." );
   }

   Console::WriteLine( "Creating a second permission with PermissionState.None." );
   IsolatedStorageFilePermission^ second = gcnew IsolatedStorageFilePermission( PermissionState::None );
   Console::WriteLine( "Does the first permission equal the second permission?: {0}", (first->Equals( second ) ? (String^)"true" : "false") );
   if ( true == first->Equals( second ) )
   {
      Console::WriteLine( "Copy_Equals demo failed because Equals returns false on two object.Equals(itself)." );
   }
}

private void Copy_EqualsDemo()
{
    Console.WriteLine("\nCopy_Equals demo.");
    Console.WriteLine("Creating the first " 
        + "IsolatedStorageFilePermission(PermissionState." 
        + "Unrestricted) permission.");
    IsolatedStorageFilePermission first = 
        new IsolatedStorageFilePermission(PermissionState.Unrestricted);
    Console.WriteLine(("Hashcode for the first permission : " 
        + System.Convert.ToString(first.GetHashCode())));
    Console.WriteLine("Copying the first permission.");
    IsolatedStorageFilePermission copyOfFirst = 
        ((IsolatedStorageFilePermission)(first.Copy()));
    Console.WriteLine(("Hashcode for copy of the first permission: " 
        + System.Convert.ToString(copyOfFirst.GetHashCode())));
    if (false == copyOfFirst.Equals(first)) {
        // This should be false, because the object references are 
        // different.
        Console.WriteLine(("The copy and the first permission " 
            + "should not be equal because they have " 
            + "\n\tdifferent object references."));
    }
    else {
        Console.WriteLine(("Error: the copy and the first " 
            + "permission should not be equal because they have " 
            + "\n\tdifferent object references."));
    }
    Console.WriteLine("Does a comparison of copy of first " 
        + "permission to itself test equal??: " 
        + ((copyOfFirst.Equals(copyOfFirst)) ? "true" : "false"));
    if (false == copyOfFirst.Equals(copyOfFirst)) {
        Console.WriteLine("Copy_Equals demo failed because Equals " 
            + "returns false on two object.Equals(itself).");
    }
    Console.WriteLine(("Does a comparison of first permission to " 
        + "itself test equal?: " 
        + ((first.Equals(first)) ? "true" : "false")));
    if (false == first.Equals(first)) {
        Console.WriteLine("Copy_Equals demo failed, because Equals " 
            + "returns false on two object.Equals(itself).");
    }
    Console.WriteLine("Creating a second permission with " 
        + "PermissionState.None.");
    IsolatedStorageFilePermission second = 
        new IsolatedStorageFilePermission(PermissionState.None);
    Console.WriteLine(("Does the first permission equal the " 
        + "second permission?: " 
        + ((first.Equals(second)) ? "true" : "false")));
    if (true == first.Equals(second)) {
        Console.WriteLine("Copy_Equals demo failed because Equals " 
            + "returns false on two object.Equals(itself).");
    }
} //Copy_EqualsDemo   

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

IsolatedStorageFilePermission-Klasse
IsolatedStorageFilePermission-Member
System.Security.Permissions-Namespace