IsolatedStorageFilePermissionとは? わかりやすく解説

IsolatedStorageFilePermission クラス

プライベート仮想ファイル システム使用できることを指定します。このクラス継承できません。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 IsolatedStorageFilePermission
    Inherits IsolatedStoragePermission
Dim instance As IsolatedStorageFilePermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class IsolatedStorageFilePermission
 : IsolatedStoragePermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class IsolatedStorageFilePermission
 sealed : public IsolatedStoragePermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class IsolatedStorageFilePermission
 extends IsolatedStoragePermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class IsolatedStorageFilePermission
 extends IsolatedStoragePermission
解説解説
使用例使用例

IsolatedStorageFilePermission クラスメンバ使用する例を次に示します

Imports System
Imports System.Security
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Security.Permissions
Imports System.Diagnostics

Public Class Demo

    ' Main method.
    Public Sub Run()
        Try
            Copy_EqualsDemo()
            To_FromXmlDemo()
            GetTypeDemo()
            IntersectDemo()
            UnionDemo()
            ToStringDemo()
            Demand_DenyDemo()
            PermitOnlyDemo()
            UserQuota_UsageDemo()
            IsSubsetOfDemo()
            IsUnrestrictedDemo()
        Catch e As Exception

            Console.WriteLine((ControlChars.Cr + ControlChars.Lf + ControlChars.Lf
 + "The demo failed due to an unexpected exception"
 + ControlChars.Cr + ControlChars.Lf + e.ToString()))
        End Try
    End Sub 'Run

    ' IsUnrestrictedDemo demonstrates the IsolatedStorageFilePermission.IsUnrestricted
 method.
    ' IsUnrestrictedDemo displays a comment indicating whether the current
 permission is unrestricted.
    Private Sub IsUnrestrictedDemo()
        Console.WriteLine("IsUnrestricted demo.")
        Try
            Dim isfp As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
            isfp.Demand() ' The permission should be unrestricted.
            Console.WriteLine("Created and demanded the IsolatedStorageFilePermission(PermissionState.Unrestricted)permission.")
            If True <> isfp.IsUnrestricted()
 Then
                Console.WriteLine("IsUnrestricted demo failed. The IsUnrestricted
 property value should be 'true'")
            End If

            isfp = New IsolatedStorageFilePermission(PermissionState.None)
            isfp.Demand() ' The permission should not be unrestricted.
            Console.WriteLine("Created and demanded the IsolatedStorageFilePermission(PermissionState.None)permission.")
            If False <> isfp.IsUnrestricted()
 Then
                Console.WriteLine("IsUnrestricted demo failed. The IsUnrestricted
 property value should be 'false'")
            End If
        Catch e As Exception
            Console.WriteLine(("Unexpected exception: "
 + e.Message))
        End Try
    End Sub 'IsUnrestrictedDemo

    ' Copy_EqualsDemo demonstrates the Copy and Equals methods.
    ' Copy creates and returns an identical copy of the current permission.
    ' Equals compares two permissions and determines whether they are
 equal.
    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

    ' To_FromXmlDemo demonstrates ToXml and FromXml.
    ' ToXml creates an XML encoding of the permission and its current
 state.
    ' FromXml reconstructs a permission with a specified state from
 an XML encoding.
    Private Sub To_FromXmlDemo()
        Console.WriteLine(ControlChars.Lf + "To_FromXML demo.")
        Dim firstPermission As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Console.WriteLine(("First permission: " +
 firstPermission.ToString()))
        Dim se As SecurityElement = firstPermission.ToXml()
        Dim secondPermission As New
 IsolatedStorageFilePermission(PermissionState.None)
        Console.WriteLine(("Second permission: " +
 secondPermission.ToString()))
        secondPermission.FromXml(se)
        Dim thirdPermission As IsolatedStorageFilePermission
 = CType(secondPermission.Intersect(firstPermission), IsolatedStorageFilePermission)
        Console.WriteLine(("Intersection of first permission and
 second permission: " + thirdPermission.ToString()))

        Try
            If False = thirdPermission.IsUnrestricted()
 Then
                Console.WriteLine("To_FromXml demo failed: The
 ToXml, FromXml roundtrip did not succeed.")
            End If
        Catch e As Exception
            Console.WriteLine("To_FromXml demo failed: An exception
 was thrown when checking the intersection")
            Console.WriteLine("of the permissions after the XML
 roundtrip.")
            Console.WriteLine(e.ToString())

            Console.WriteLine(e.ToString())
        End Try
    End Sub 'To_FromXmlDemo

    ' GetType demonstrates the GetType method.
    ' This method returns the type of the current instance.
    Private Sub GetTypeDemo()
        Console.WriteLine(ControlChars.Lf + "GetType demo.")
        Dim isfp As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp1 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)

        If 0 <> isfp.GetType().ToString().CompareTo("System.Security.Permissions.IsolatedStorageFilePermission")
 Then
            Console.WriteLine(("GetType returned the wrong value:
 " + isfp.GetType().ToString()))
        Else
            Console.WriteLine(("GetType returned: "
 + isfp.GetType().ToString()))
        End If
    End Sub 'GetTypeDemo

    ' IntersectDemo demonstrates the Intersect method.
    ' CIntersect creates and returns a permission that is the intersection
 of the current permission
    ' and the specified permission.
    ' Note  The intersection of two PermissionState.None permissions
 *IS* null. 
    Private Sub IntersectDemo()
        Console.WriteLine(ControlChars.Lf + "Intersect demo.")
        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp1 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp2 As New
 IsolatedStorageFilePermission(PermissionState.None)
        Dim isfp3 As New
 IsolatedStorageFilePermission(PermissionState.None)

        Dim t As IsolatedStorageFilePermission
 = CType(isfp0.Intersect(isfp1), IsolatedStorageFilePermission)
        If True = t.IsUnrestricted() Then
            Console.WriteLine("The intersection of two PermissionState.Unrestricted
 permissions is unrestricted.")
        Else
            Console.WriteLine(("Intersect demo failed because
 the intersection of two unrestricted permissions " + ControlChars.Lf
 + ControlChars.Tab + "should be unrestricted."))
        End If

        t = CType(isfp0.Intersect(isfp2), IsolatedStorageFilePermission)
        If False = t.IsUnrestricted() Then
            Console.WriteLine(("The intersection of a PermissionState.Unrestricted
 and " + ControlChars.Lf + ControlChars.Tab + "PermissionState.None
 permission is not unrestricted."))
        Else
            Console.WriteLine(("Intersect demo failed because
 the intersection of a unrestricted and " + ControlChars.Lf + ControlChars.Tab
 + "none permission should be none."))
        End If


        ' The permission set that comes back from this intersection
 is null.
        t = CType(isfp2.Intersect(isfp3), IsolatedStorageFilePermission)
        If Nothing Is t
 Then
            Console.WriteLine("The intersection of two PermissionState.None
 permissions is null.")
        Else
            Console.WriteLine(("Intersect failed because the intersection
 of two PermissionState.None permissions " + ControlChars.Lf + ControlChars.Tab
 + "should be null."))
        End If
    End Sub 'IntersectDemo

    ' UnionDemo demonstrates the Union method.
    ' Union creates a permission that is the union of the current permission
 and the specified permission.
    ' Note: The union of two PermissionState.None permissions is *NOT*
 null.
    Private Sub UnionDemo()
        Console.WriteLine(ControlChars.Lf + "Union demo.")
        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp1 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp2 As New
 IsolatedStorageFilePermission(PermissionState.None)
        Dim isfp3 As New
 IsolatedStorageFilePermission(PermissionState.None)

        Dim t As IsolatedStorageFilePermission
 = CType(isfp0.Union(isfp1), IsolatedStorageFilePermission)
        If True = t.IsUnrestricted() Then
            Console.WriteLine("The union of two PermissionState.Unrestricted
 permissions is unrestricted.")
        Else
            Console.WriteLine(("Union demo failed because the
 union of two PermissionState.Unrestricted permissions " + ControlChars.Lf
 + ControlChars.Tab + "should be unrestricted"))
        End If

        t = CType(isfp0.Union(isfp2), IsolatedStorageFilePermission)
        If True = t.IsUnrestricted() Then
            Console.WriteLine(("The union of a PermissionState.Unrestricted
 and a PermissionState.None " + ControlChars.Lf + ControlChars.Tab +
 "permission is unrestricted."))
        Else
            Console.WriteLine(("Union demo failed because the
 union of a PermissionState.Unrestricted and a " + ControlChars.Lf +
 ControlChars.Tab + "PermissionState.None permission should be unrestricted."))
        End If


        t = CType(isfp2.Union(isfp3), IsolatedStorageFilePermission)
        If Nothing Is t
 Then
            Console.WriteLine("Union failed because the union
 of two PermissionState.None permissions should not be null.")
            Console.WriteLine(t.ToString())
        Else
            Console.WriteLine("The union of two PermissionState.None
 permissions is none.")
        End If
    End Sub 'UnionDemo

    ' ToStringDemo demonstrates the ToString method.
    ' ToString creates and returns a string representation of the current
 permission object.
    Private Sub ToStringDemo()
        Console.WriteLine(ControlChars.Lf + "ToString demo.")
        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim PermString As [String] = isfp0.ToString()

        Dim PermStringParts As [String]() =
 {"class=", "mscorlib",
 "Version=", "Culture=", "PublicKeyToken=", "version=",
 "Unrestricted="}


        Dim part As [String]
        For Each part In
 PermStringParts
            If PermString.IndexOf(part) >= 0 Then
                Console.WriteLine((part + " found in the string."))
            Else
                Console.WriteLine("ToString demo failed because
 [{0}] was not found.", part)
            End If
        Next part
    End Sub 'ToStringDemo

    ' Demand_Deny demonstrates Demand and Deny.
    ' Demand forces a SecurityException at run time if all callers higher
 in the call stack 
    ' have not been granted the permission specified by the current
 instance.
    ' Deny prevents callers higher in the call stack from using the
 code that calls this method to 
    ' access the resource specified by the current instance.
    Private Sub Demand_DenyDemo()
        Console.WriteLine(ControlChars.Lf + "Demand_Deny demo.")
        Console.WriteLine("Denying a permission with PermissionState.Unrestricted.")
        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        isfp0.Deny()
        Try
            Console.WriteLine("Denying permission a second time.")
            isfp0.Deny()
        Catch e As SecurityException
            Console.WriteLine("SecurityException was thrown as
 expected.")
        Catch e As Exception
            Console.WriteLine(("Demand_Deny demo failed because
 an unexpected exception was thrown" + ControlChars.Lf + ControlChars.Tab
 + "when making a second call to Deny()" + ControlChars.Cr + ControlChars.Lf + e.ToString()))
        End Try
        Console.WriteLine("Reverting the deny.")
        IsolatedStorageFilePermission.RevertDeny()

        If 0 <> DoDemand() Then
            Console.WriteLine("Demand_Deny demo failed because
 an unexpected exception was thrown during a demand.")
        End If

        isfp0.Deny()
        If 1 <> DoDemand() Then
            Console.WriteLine("Demand_Deny demo failed because
 the expected SecurityException was not thrown during a demand.")
        End If

        IsolatedStorageFilePermission.RevertDeny()
        If 0 <> DoDemand() Then
            Console.WriteLine("Demand_Deny demo failed because
 an unexpected exception was thrown during a demand.")
        End If
    End Sub 'Demand_DenyDemo

    ' PermitOnly demonstrates the PermitOnly method.
    ' PermitOnly prevents callers higher in the call stack from using
 the code that calls this method to 
    ' access all resources except for the resource specified by the
 current instance.
    Private Sub PermitOnlyDemo()
        Console.WriteLine(ControlChars.Lf + "PermitOnly demo.")

        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        isfp0.Demand()
        isfp0.PermitOnly()
        Try
            isfp0.PermitOnly()
        Catch e As SecurityException
            Console.WriteLine("The second call to PermitOnly caused
 an exception as expected.")
        Catch e As Exception
            Console.WriteLine(("PermitOnly demo failed because
 an unexpected exception was thrown" + ControlChars.Lf + ControlChars.Tab
 + "when making a second call to PermitOnly()" + ControlChars.Cr + ControlChars.Lf + e.ToString()))
        End Try

        IsolatedStorageFilePermission.RevertPermitOnly()
        If 0 <> DemandUI() Then
            Console.WriteLine("PermitOnly demo failed because
 an exception was thrown during a demand for UI permissions.")
            Console.WriteLine("We weren't expecting this.")
        End If

        isfp0.PermitOnly()
        If 1 <> DemandUI() Then
            Console.WriteLine(("PermitOnly demo failed because
 a SecurityException was not thrown, " + ControlChars.Lf + ControlChars.Tab
 + "during a demand for UI permissions.  A SecurityException was expected."))
        End If


        IsolatedStorageFilePermission.RevertPermitOnly()
        If 0 <> DoDemand() Then
            Console.WriteLine("PermitOnly failed because an exception
 was thrown during a demand for UI permissions.")
            Console.WriteLine("We weren't expecting this.")
        End If
    End Sub 'PermitOnlyDemo

    ' UserQuota_UsageDemo demonstrates UserQuota and UsageAllowed properties.
    ' UserQuota gets or sets the quota on the overall size of each user's
 total store.  
    ' This property is inherited from IsolatedStoragePermission.UserQuota.
    ' UsageAllowed gets or sets the type of isolated storage containment
 allowed.  
    ' This property is inherited from IsolatedStoragePermission.UsageAllowed.
    ' Note  You can set UsageAllowed to None, but you cannot set UserQuota
 to 0.
    ' Also note that trying to set UsageAllowed or UserQuota to values
 that are currently set
    ' will throw an exception.  
    <IsolatedStorageFilePermissionAttribute(SecurityAction.Deny, _
    UsageAllowed:=IsolatedStorageContainment.DomainIsolationByRoamingUser, UserQuota:=100)>
 _
   Private Sub UserQuota_UsageDemo()
        Console.WriteLine(ControlChars.Lf + "UserQuota_Usage demo.")
        Dim returnValue As Boolean
 = False

        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.None)

        Console.WriteLine("Checking UsageAllowed for IsolatedStorageContainment.None")
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.None, False)
        If Not returnValue Then
            Console.WriteLine("IsolatedStorageContainment.None
 demo failed")
        End If

        Console.WriteLine("Checking UsageAllowed for IsolatedStorageContainment.DomainIsolationByRoamingUser.")
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.DomainIsolationByRoamingUser,
 True)
        If Not returnValue Then
            Console.WriteLine("IsolatedStorageContainment.DomainIsolationByRoamingUser
 failed")
        End If

        Console.WriteLine("Checking UsageAllowed for IsolatedStorageContainment.AssemblyIsolationByUser.")
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.AssemblyIsolationByUser,
 True)
        If Not returnValue Then
            Console.WriteLine("IsolatedStorageContainment.AssemblyIsolationByUse
 failed")
        End If

        Console.WriteLine("Requesting UserQuota of 0.")
        returnValue = UserQuota(isfp0, 0, True)
        If Not returnValue Then
            Console.WriteLine("UserQuota 0 failed")
        End If

        Console.WriteLine("Requesting UserQuota of 100.")
        returnValue = UserQuota(isfp0, 100, True)
        If Not returnValue Then
            Console.WriteLine("UserQuota 100 failed")
        End If

        Console.WriteLine("Requesting UserQuota of -2147483648.")
        returnValue = UserQuota(isfp0, -2147483648, True)

        If Not returnValue Then
            Console.WriteLine("UserQuota -214748364 failed")
        End If
    End Sub 'UserQuota_UsageDemo

    ' IsSubsetOfDemo demonstrates the IsSubsetOf method.
    ' IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
    Private Sub IsSubsetOfDemo()
        Console.WriteLine(ControlChars.Lf + "IsSubsetOf demo.")

        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.None)
        Dim isfp1 As New
 IsolatedStorageFilePermission(PermissionState.None)
        Dim isfp2 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Dim isfp3 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)

        If isfp0.IsSubsetOf(isfp1) Then
            Console.WriteLine("PermissionState.None is a subset
 of PermissionState.None.")
        Else
            Console.WriteLine("IsSubsetOfDemo failed: PermissionState.None
 should be a subset of PermissionState.None")
        End If

        If isfp0.IsSubsetOf(isfp2) Then
            Console.WriteLine("PermissionState.None is a subset
 of PermissionState.Unrestricted.")
        Else
            Console.WriteLine("IsSubsetOfDemo failed: PermissionState.None
 should be a subset of PermissionState.Unrestricted")
        End If

        If Not isfp2.IsSubsetOf(isfp0) Then
            Console.WriteLine("PermissionState.Unrestricted is
 not a subset of PermissionState.None.")
        Else
            Console.WriteLine(("IsSubsetOfDemo failed: PermissionState.Unrestricted
 should not be a subset " + ControlChars.Lf + ControlChars.Tab + "of
 PermissionState.None"))
        End If

        If isfp2.IsSubsetOf(isfp3) Then
            Console.WriteLine("PermissionState.Unrestricted is
 a subset of PermissionState.Unrestricted.")
        Else
            Console.WriteLine(("IsSubsetOfDemo failed: Permissionstate.Unrestricted
 should be a subset of " + ControlChars.Lf + ControlChars.Tab + "PermissionState.Unrestricted"))
        End If
    End Sub 'IsSubsetOfDemo

    ' **********************************************************************
    ' The following methods are simple helper functions.
    ' **********************************************************************
    ' **********************************************************************
    ' UserQuota
    ' Sets UserQuota to the value that was passed in.
    '
    Private Function UserQuota(ByVal
 isfp As IsolatedStorageFilePermission, ByVal
 user_quota As Integer, ByVal exception_expected As Boolean) As
 Boolean
        Dim ExceptionCaught As Boolean
 = False
        isfp.UserQuota = user_quota

        Try
            isfp.Demand()
        Catch e As Exception
            ExceptionCaught = True
            If Not exception_expected Then
                Console.WriteLine("An unexpected exception was
 thrown when setting UserQuota value [{0}]", user_quota.ToString())
                Console.WriteLine(("Exception: " +
 ControlChars.Cr + ControlChars.Lf + e.ToString()))
            End If
        End Try

        If Not ExceptionCaught AndAlso
 exception_expected Then
            Console.WriteLine("An expected exception not thrown
 when setting UserQuota value [{0}]", user_quota.ToString())
        End If

        Return True
    End Function 'UserQuota


    ' **********************************************************************
    ' UsageAllowed
    ' This method sets UsageAllowed to the value that was passed in.
    '
    Private Function UsageAllowed(ByVal
 isfp As IsolatedStorageFilePermission, ByVal
 isc As IsolatedStorageContainment, ByVal exception_expected As Boolean) As Boolean
        Dim ExceptionCaught As Boolean
 = False
        isfp.UsageAllowed = isc
        Try
            isfp.Demand()
        Catch e As Exception
            ExceptionCaught = True
            If Not exception_expected Then

                Console.WriteLine("An unexpected exception was
 thrown when setting IsolatedStorageContainment value [{0}]", isc.ToString())
                Console.WriteLine(("Exception: " +
 ControlChars.Cr + ControlChars.Lf + e.ToString()))
            End If
        End Try

        If Not ExceptionCaught AndAlso
 exception_expected Then
            Console.WriteLine("An expected exception was not thrown
 when setting IsolatedStorageContainment value [{0}]", isc.ToString())
        End If

        Return True
    End Function 'UsageAllowed



    ' **********************************************************************
    ' DoDemand()
    ' This method demands an IsolatedStorageFilePermission.
    Private Function DoDemand() As
 Integer
        Dim ReturnValue As Integer
 = 0
        Dim isfp0 As New
 IsolatedStorageFilePermission(PermissionState.Unrestricted)
        Try
            isfp0.Demand()
        Catch e As SecurityException
            ReturnValue = 1
        Catch e As Exception
            Console.WriteLine(("An unexpected exception was thrown
 in DoDemand" + ControlChars.Cr + ControlChars.Lf + e.ToString()))
            ReturnValue = -1
        End Try

        Return ReturnValue
    End Function 'DoDemand


    ' **********************************************************************
    ' DemandUI()
    ' This method demands a UIPermission
    ' Returns:
    '    0 if the demand was successful.
    '    1 if a SecurityException was thrown.
    '    -1 if an unexpected exception was thrown.
    '
    Private Function DemandUI() As
 Integer
        Dim ReturnValue As Integer
 = 0
        Dim MyPermission As New
 UIPermission(PermissionState.Unrestricted)
        Try
            MyPermission.Demand()
        Catch e As SecurityException
            ReturnValue = 1
        Catch e As Exception
            Console.WriteLine(("An unexpected exception was thrown
 in DemandUI" + ControlChars.Cr + ControlChars.Lf + e.ToString()))
        End Try

        Return ReturnValue
    End Function 'DemandUI

    Public Overloads Shared
 Function Main(ByVal args() As
 [String]) As Integer
        Dim MyDemo As New
 Demo

        MyDemo.Run()
        Return 0
    End Function 'Main
End Class 'Demo
using System;
using System.Security;
using System.IO;
using System.IO.IsolatedStorage;
using System.Security.Permissions;
using System.Diagnostics;

public class Demo
{
    // Main method.
    public void Run()
    {
        try
        {
            Copy_EqualsDemo();
            To_FromXmlDemo();
            GetTypeDemo();
            IntersectDemo();
            UnionDemo();
            ToStringDemo();
            Demand_DenyDemo();
            PermitOnlyDemo();
            UserQuota_UsageDemo();
            IsSubsetOfDemo();
            IsUnrestrictedDemo();
        }
        catch (Exception e)
        {

            Console.WriteLine("\r\n\nThe demo failed due to an unexpected exception\r\n"+e.ToString());
        }
    }




    // IsUnrestrictedDemo demonstrates the IsolatedStorageFilePermission.IsUnrestricted
 method.
    // IsUnrestrictedDemo displays a comment indicating whether the
 current permission is unrestricted.
    private void IsUnrestrictedDemo()
    {
        Console.WriteLine("IsUnrestricted demo.");
        try
        {
            IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
            isfp.Demand(); // The permission should be unrestricted.
            Console.WriteLine
                ("Created and demanded the IsolatedStorageFilePermission(PermissionState.Unrestricted)permission."
 );
            if ( true != isfp.IsUnrestricted()
 )
            {
                Console.WriteLine
                    ("IsUnrestricted demo failed. The IsUnrestricted property
 value should be 'true'");
            }

            isfp = new IsolatedStorageFilePermission(PermissionState.None);
            isfp.Demand(); // The permission should not be unrestricted.
            Console.WriteLine
                ("Created and demanded the IsolatedStorageFilePermission(PermissionState.None)permission.");
            if ( false != isfp.IsUnrestricted()
 )
            {
                Console.WriteLine
                    ("IsUnrestricted demo failed. The IsUnrestricted property
 value should be 'false'");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine
                ("Unexpected exception: " + e.Message);
        }

    }

    // Copy_EqualsDemo demonstrates the Copy and Equals methods.
    // Copy creates and returns an identical copy of the current permission.
    // Equals compares two permissions and determines whether they are
 equal.
    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).");
        }
    }

    // To_FromXmlDemo demonstrates ToXml and FromXml.
    // ToXml creates an XML encoding of the permission and its current
 state.
    // FromXml reconstructs a permission with a specified state from
 an XML encoding.
    private void To_FromXmlDemo()
    {
        Console.WriteLine
            ("\nTo_FromXML demo.");
        IsolatedStorageFilePermission firstPermission = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        Console.WriteLine
            ("First permission: " + firstPermission.ToString());
        SecurityElement se = firstPermission.ToXml();
        IsolatedStorageFilePermission secondPermission = new IsolatedStorageFilePermission(PermissionState.None);
        Console.WriteLine
            ("Second permission: " + secondPermission.ToString());
        secondPermission.FromXml(se);
        IsolatedStorageFilePermission thirdPermission = (IsolatedStorageFilePermission)secondPermission.Intersect(firstPermission);
        Console.WriteLine
            ("Intersection of first permission and second permission: "
 + thirdPermission.ToString());

        try
        {
            if (false == thirdPermission.IsUnrestricted())
            {
                Console.WriteLine
                    ("To_FromXml demo failed: The ToXml, FromXml roundtrip did
 not succeed.");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("To_FromXml demo failed: An exception was thrown
 when checking the intersection");
            Console.WriteLine("of the permissions after the XML roundtrip.");
            Console.WriteLine(e.ToString());

            Console.WriteLine(e.ToString());
        }

    }

    // GetType demonstrates the GetType method.
    // This method returns the type of the current instance.
    private void GetTypeDemo()
    {
        Console.WriteLine("\nGetType demo.");
        IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);

        if (0 != isfp.GetType().ToString().CompareTo("System.Security.Permissions.IsolatedStorageFilePermission"))
        {
            Console.WriteLine
                ("GetType returned the wrong value: " + isfp.GetType().ToString());
        }
        else
        {
            Console.WriteLine
                ("GetType returned: " + isfp.GetType().ToString());
        }
    }
    // IntersectDemo demonstrates the Intersect method.
    // CIntersect creates and returns a permission that is the intersection
 of the current permission
    // and the specified permission.
    // Note The intersection of two PermissionState.None permissions
 *IS* null.
    private void IntersectDemo()
    {
        Console.WriteLine("\nIntersect demo.");
        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp2 = new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp3 = new IsolatedStorageFilePermission(PermissionState.None);

        IsolatedStorageFilePermission t = (IsolatedStorageFilePermission)isfp0.Intersect(isfp1);
        if (true == t.IsUnrestricted())
        {
            Console.WriteLine
                ("The intersection of two PermissionState.Unrestricted permissions
 is unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("Intersect demo failed because the intersection of two unrestricted
 permissions " +
                "\n\tshould be unrestricted.");
        }

        t = (IsolatedStorageFilePermission)isfp0.Intersect(isfp2);
        if (false == t.IsUnrestricted())
        {
            Console.WriteLine
                ("The intersection of a PermissionState.Unrestricted and "
 +
                "\n\tPermissionState.None permission is not unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("Intersect demo failed because the intersection of a unrestricted
 and " +
                "\n\tnone permission should be none.");
        }


        // The permission set that comes back from this intersection
 is null.
        t = (IsolatedStorageFilePermission)isfp2.Intersect(isfp3);
        if (null == t)
        {
            Console.WriteLine
                ("The intersection of two PermissionState.None permissions is
 null.");
        }
        else
        {
            Console.WriteLine
                ("Intersect failed because the intersection of two PermissionState.None
 permissions " +
                "\n\tshould be null.");
        }

    }

    // UnionDemo demonstrates the Union method.
    // Union creates a permission that is the union of the current permission
 and the specified permission.
    // Note: The union of two PermissionState.None permissions is *NOT*
 null.
    private void UnionDemo()
    {
        Console.WriteLine("\nUnion demo.");
        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp2 = new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp3 = new IsolatedStorageFilePermission(PermissionState.None);

        IsolatedStorageFilePermission t = (IsolatedStorageFilePermission)isfp0.Union(isfp1);
        if (true == t.IsUnrestricted())
        {
            Console.WriteLine("The union of two PermissionState.Unrestricted
 permissions is unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("Union demo failed because the union of two PermissionState.Unrestricted
 permissions " +
                "\n\tshould be unrestricted");
        }

        t = (IsolatedStorageFilePermission)isfp0.Union(isfp2);
        if (true == t.IsUnrestricted())
        {
            Console.WriteLine
                ("The union of a PermissionState.Unrestricted and a PermissionState.None
 " +
                "\n\tpermission is unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("Union demo failed because the union of a PermissionState.Unrestricted
 and a " +
                "\n\tPermissionState.None permission should be unrestricted.");
        }


        t = (IsolatedStorageFilePermission)isfp2.Union(isfp3);
        if (null != t)
        {
            Console.WriteLine("The union of two PermissionState.None permissions
 is none.");
        }
        else
        {
            Console.WriteLine
                ("Union failed because the union of two PermissionState.None
 permissions should not be null.");
            Console.WriteLine(t.ToString());
        }
    }

    // ToStringDemo demonstrates the ToString method.
    // ToString creates and returns a string representation of the current
 permission object.
    private void ToStringDemo()
    {
        Console.WriteLine("\nToString demo.");
        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        String PermString = isfp0.ToString();

        String[] PermStringParts = {"class=" ,"mscorlib"
 ,"Version=" ,"Culture=" ,"PublicKeyToken="
                                       ,"version=" ,"Unrestricted="};


        foreach (String part in PermStringParts)
        {
            if (PermString.IndexOf(part) >= 0)
            {
                Console.WriteLine(part + " found in the string.");
            }
            else
            {
                Console.WriteLine("ToString demo failed because [{0}] was not
 found.", part);
            }
        }

    }

    // Demand_Deny demonstrates Demand and Deny.
    // Demand forces a SecurityException at run time if all callers
 higher in the call stack
    // have not been granted the permission specified by the current
 instance.
    // Deny prevents callers higher in the call stack from using the
 code that calls this method to
    // access the resource specified by the current instance.
    private void Demand_DenyDemo()
    {
        Console.WriteLine("\nDemand_Deny demo.");
        Console.WriteLine("Denying a permission with PermissionState.Unrestricted.");
        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        isfp0.Deny();
        try
        {
            Console.WriteLine("Denying permission a second time.");
            isfp0.Deny();
        }
        catch (SecurityException)
        {
            Console.WriteLine("SecurityException was thrown as expected.");
        }
        catch (Exception e)
        {
            Console.WriteLine
                ("Demand_Deny demo failed because an unexpected exception was
 thrown" +
                "\n\twhen making a second call to Deny()\r\n" + e.ToString());
        }
        Console.WriteLine("Reverting the deny.");
        IsolatedStorageFilePermission.RevertDeny();

        if (0 != DoDemand())
        {
            Console.WriteLine
                ("Demand_Deny demo failed because an unexpected exception was
 thrown during a demand.");
        }

        isfp0.Deny();
        if (1 != DoDemand())
        {
            Console.WriteLine
                ("Demand_Deny demo failed because the expected SecurityException
 was not thrown during a demand.");
        }

        IsolatedStorageFilePermission.RevertDeny();
        if (0 != DoDemand())
        {
            Console.WriteLine
                ("Demand_Deny demo failed because an unexpected exception was
 thrown during a demand.");
        }
    }

    // PermitOnly demonstrates the PermitOnly method.
    // PermitOnly prevents callers higher in the call stack from using
 the code that calls this method to
    // access all resources except for the resource specified by the
 current instance.
    private void PermitOnlyDemo()
    {
        Console.WriteLine("\nPermitOnly demo.");

        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        isfp0.Demand();
        isfp0.PermitOnly();
        try
        {
            isfp0.PermitOnly();
        }
        catch (SecurityException)
        {
            Console.WriteLine
                ("The second call to PermitOnly caused an exception as expected.");
        }
        catch (Exception e)
        {
            Console.WriteLine
                ("PermitOnly demo failed because an unexpected exception was
 thrown" +
                "\n\twhen making a second call to PermitOnly()\r\n" + e.ToString());
        }

        IsolatedStorageFilePermission.RevertPermitOnly();
        if (0 != DemandUI())
        {
            Console.WriteLine
                ("PermitOnly demo failed because an exception was thrown during
 a demand for UI permissions.");
            Console.WriteLine
                ("We weren't expecting this.");
        }

        isfp0.PermitOnly();
        if (1 != DemandUI())
        {
            Console.WriteLine
                ("PermitOnly demo failed because a SecurityException was not
 thrown, " +
                "\n\tduring a demand for UI permissions.
 A SecurityException was expected.");

        }

        IsolatedStorageFilePermission.RevertPermitOnly();
        if (0 != DoDemand())
        {
            Console.WriteLine
                ("PermitOnly failed because an exception was thrown during a
 demand for UI permissions.");
            Console.WriteLine("We weren't expecting this.");
        }

    }


    // UserQuota_UsageDemo demonstrates UserQuota and UsageAllowed properties.
    // UserQuota gets or sets the quota on the overall size of each
 user's total store.
    // This property is inherited from IsolatedStoragePermission.UserQuota.
    // UsageAllowed gets or sets the type of isolated storage containment
 allowed.
    // This property is inherited from IsolatedStoragePermission.UsageAllowed.
    // Note You can set UsageAllowed to None, but you cannot set UserQuota
 to 0.
    // Also note that trying to set UsageAllowed or UserQuota to values
 that are currently set
    // will throw an exception.
    [method:IsolatedStorageFilePermissionAttribute(SecurityAction.Deny, UsageAllowed
 = IsolatedStorageContainment.DomainIsolationByRoamingUser, UserQuota=100)]
    private void UserQuota_UsageDemo()
    {
        Console.WriteLine
            ("\nUserQuota_Usage demo.");
        bool returnValue = false;

        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.None);

        Console.WriteLine
            ("Checking UsageAllowed for IsolatedStorageContainment.None");
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.None, false);
        if (!returnValue)
            Console.WriteLine
                ("IsolatedStorageContainment.None demo failed");

        Console.WriteLine
            ("Checking UsageAllowed for IsolatedStorageContainment.DomainIsolationByRoamingUser.");
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.DomainIsolationByRoamingUser,
 true);
        if (!returnValue)
            Console.WriteLine
                ("IsolatedStorageContainment.DomainIsolationByRoamingUser failed");

        Console.WriteLine
            ("Checking UsageAllowed for IsolatedStorageContainment.AssemblyIsolationByUser.");
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.AssemblyIsolationByUser,
 true);
        if (!returnValue)
            Console.WriteLine
                ("IsolatedStorageContainment.AssemblyIsolationByUse failed");

        Console.WriteLine
            ("Requesting UserQuota of 0.");
        returnValue = UserQuota(isfp0, 0, true);
        if (!returnValue)
            Console.WriteLine
                ("UserQuota 0 failed");

        Console.WriteLine
            ("Requesting UserQuota of 100.");
        returnValue = UserQuota(isfp0, 100, true);
        if (!returnValue)
            Console.WriteLine
                ("UserQuota 100 failed");

        Console.WriteLine
            ("Requesting UserQuota of -2147483648.");
        returnValue = UserQuota(isfp0, -2147483648, true);
        if (!returnValue)
            Console.WriteLine
                ("UserQuota -214748364 failed");
    }

    // IsSubsetOfDemo demonstrates the IsSubsetOf method.
    // IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
    private void IsSubsetOfDemo()
    {
        Console.WriteLine("\nIsSubsetOf demo.");

        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp1 = new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp2 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp3 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);

        if (isfp0.IsSubsetOf(isfp1))
        {
            Console.WriteLine
                ("PermissionState.None is a subset of PermissionState.None.");
        }
        else
        {
            Console.WriteLine
                ("IsSubsetOfDemo failed: PermissionState.None should be a subset
 of PermissionState.None");
        }

        if (isfp0.IsSubsetOf(isfp2))
        {
            Console.WriteLine
                ("PermissionState.None is a subset of PermissionState.Unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("IsSubsetOfDemo failed: PermissionState.None should be a subset
 of PermissionState.Unrestricted");
        }

        if (!isfp2.IsSubsetOf(isfp0))
        {
            Console.WriteLine
                ("PermissionState.Unrestricted is not a subset of PermissionState.None.");
        }
        else
        {
            Console.WriteLine
                ("IsSubsetOfDemo failed: PermissionState.Unrestricted should
 not be a subset " +
                "\n\tof PermissionState.None");
        }

        if (isfp2.IsSubsetOf(isfp3))
        {
            Console.WriteLine
                ("PermissionState.Unrestricted is a subset of PermissionState.Unrestricted.");
        }
        else
        {
            Console.WriteLine
                ("IsSubsetOfDemo failed: Permissionstate.Unrestricted should
 be a subset of " +
                "\n\tPermissionState.Unrestricted");
        }

    }

    // **********************************************************************
    // The following methods are simple helper functions.
    // **********************************************************************

    // **********************************************************************
    // UserQuota
    // Sets UserQuota to the value that was passed in.
    //

    private bool UserQuota(IsolatedStorageFilePermission
 isfp, int user_quota, bool exception_expected)
    {
        bool ExceptionCaught = false;
        isfp.UserQuota = user_quota;

        try
        {
            isfp.Demand();
        }
        catch (Exception e)
        {
            ExceptionCaught = true;
            if (!exception_expected)
            {
                Console.WriteLine
                    ("An unexpected exception was thrown when setting UserQuota
 value [{0}]", user_quota.ToString());
                Console.WriteLine("Exception: \r\n" + e.ToString());
            }
        }

        if ((!ExceptionCaught) && exception_expected)
        {
            Console.WriteLine
                ("An expected exception not thrown when setting UserQuota value
 [{0}]", user_quota.ToString());
        }

        return true;
    }

    // **********************************************************************
    // UsageAllowed
    // This method sets UsageAllowed to the value that was passed in.
    //

    private bool UsageAllowed(IsolatedStorageFilePermission
 isfp, IsolatedStorageContainment isc, bool exception_expected)
    {
        bool ExceptionCaught = false;
        isfp.UsageAllowed = isc;
        try
        {
            isfp.Demand();
        }
        catch (Exception e)
        {
            ExceptionCaught = true;
            if (!exception_expected)

            {
                Console.WriteLine
                    ("An unexpected exception was thrown when setting IsolatedStorageContainment
 value [{0}]", isc.ToString());
                Console.WriteLine("Exception: \r\n" + e.ToString());
            }
        }

        if ((!ExceptionCaught) && exception_expected)
        {
            Console.WriteLine
                ("An expected exception was not thrown when setting IsolatedStorageContainment
 value [{0}]", isc.ToString());
        }

        return true;
    }


    // **********************************************************************
    // DoDemand()
    // This method demands an IsolatedStorageFilePermission.

    private int DoDemand()
    {
        int ReturnValue = 0;
        IsolatedStorageFilePermission isfp0 = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        try
        {
            isfp0.Demand();
        }
        catch (SecurityException)
        {
            ReturnValue = 1;
        }
        catch (Exception e)
        {
            Console.WriteLine
                ("An unexpected exception was thrown in DoDemand\r\n"
 + e.ToString());
            ReturnValue = -1;
        }

        return ReturnValue;
    }

    // **********************************************************************
    // DemandUI()
    // This method demands a UIPermission
    // Returns:
    // 0 if the demand was successful.
    // 1 if a SecurityException was thrown.
    // -1 if an unexpected exception was thrown.
    //
    private int DemandUI()
    {
        int ReturnValue = 0;
        UIPermission MyPermission = new UIPermission(PermissionState.Unrestricted);
        try
        {
            MyPermission.Demand();
        }
        catch (SecurityException)
        {
            ReturnValue = 1;
        }
        catch (Exception e)
        {
            Console.WriteLine("An unexpected exception was thrown in
 DemandUI\r\n" + e.ToString());
        }

        return ReturnValue;
    }


    public static int Main(String[]
 args)
    {
        Demo MyDemo = new Demo();

        MyDemo.Run();
        return 0 ;
    }
}
using namespace System;
using namespace System::Security;
using namespace System::IO;
using namespace System::IO::IsolatedStorage;
using namespace System::Security::Permissions;
using namespace System::Diagnostics;
public ref class Demo
{
public:

   // Main method.
   void Run()
   {
      try
      {
         Copy_EqualsDemo();
         To_FromXmlDemo();
         GetTypeDemo();
         IntersectDemo();
         UnionDemo();
         ToStringDemo();
         Demand_DenyDemo();
         PermitOnlyDemo();
         UserQuota_UsageDemo();
         IsSubsetOfDemo();
         IsUnrestrictedDemo();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "\r\n\nThe demo failed due to an unexpected exception\r\n{0}",
 e );
      }

   }


private:

   // IsUnrestrictedDemo demonstrates the IsolatedStorageFilePermission.IsUnrestricted
 method.
   // IsUnrestrictedDemo displays a comment indicating whether the current
 permission is unrestricted.
   void IsUnrestrictedDemo()
   {
      Console::WriteLine( "IsUnrestricted demo." );
      try
      {
         IsolatedStorageFilePermission^ isfp = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
         isfp->Demand(); // The permission should be unrestricted.
         Console::WriteLine( "Created and demanded the IsolatedStorageFilePermission(PermissionState.Unrestricted)permission."
 );
         if ( true != isfp->IsUnrestricted()
 )
         {
            Console::WriteLine( "IsUnrestricted demo failed. The IsUnrestricted
 property value should be 'true'" );
         }
         isfp = gcnew IsolatedStorageFilePermission( PermissionState::None );
         isfp->Demand(); // The permission should not be unrestricted.
         Console::WriteLine( "Created and demanded the IsolatedStorageFilePermission(PermissionState.None)permission."
 );
         if ( false != isfp->IsUnrestricted()
 )
         {
            Console::WriteLine( "IsUnrestricted demo failed. The IsUnrestricted
 property value should be 'false'" );
         }
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Unexpected exception: {0}", e->Message
 );
      }

   }


   // Copy_EqualsDemo demonstrates the Copy and Equals methods.
   // Copy creates and returns an identical copy of the current permission.
   // Equals compares two permissions and determines whether they are
 equal.
   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)." );
      }
   }


   // To_FromXmlDemo demonstrates ToXml and FromXml.
   // ToXml creates an XML encoding of the permission and its current
 state.
   // FromXml reconstructs a permission with a specified state from
 an XML encoding.
   void To_FromXmlDemo()
   {
      Console::WriteLine( "\nTo_FromXML demo." );
      IsolatedStorageFilePermission^ firstPermission = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      Console::WriteLine( "First permission: {0}", firstPermission );
      SecurityElement^ se = firstPermission->ToXml();
      IsolatedStorageFilePermission^ secondPermission = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      Console::WriteLine( "Second permission: {0}", secondPermission );
      secondPermission->FromXml( se );
      IsolatedStorageFilePermission^ thirdPermission = dynamic_cast<IsolatedStorageFilePermission^>(secondPermission->Intersect(
 firstPermission ));
      Console::WriteLine( "Intersection of first permission and second permission:
 {0}", thirdPermission );
      try
      {
         if ( false == thirdPermission->IsUnrestricted()
 )
         {
            Console::WriteLine( "To_FromXml demo failed: The ToXml, FromXml
 roundtrip did not succeed." );
         }
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "To_FromXml demo failed: An exception was thrown
 when checking the intersection" );
         Console::WriteLine( "of the permissions after the XML roundtrip."
 );
         Console::WriteLine( e );
         Console::WriteLine( e );
      }

   }


   // GetType demonstrates the GetType method.
   // This method returns the type of the current instance.
   void GetTypeDemo()
   {
      Console::WriteLine( "\nGetType demo." );
      IsolatedStorageFilePermission^ isfp = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp1 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      if ( 0 != isfp->GetType()->ToString()->CompareTo(
 "System.Security.Permissions.IsolatedStorageFilePermission" ) )
      {
         Console::WriteLine( "GetType returned the wrong value: {0}", isfp->GetType()
 );
      }
      else
      {
         Console::WriteLine( "GetType returned: {0}", isfp->GetType()
 );
      }
   }


   // IntersectDemo demonstrates the Intersect method.
   // CIntersect creates and returns a permission that is the intersection
 of the current permission
   // and the specified permission.
   // Note  The intersection of two PermissionState.None permissions
 *IS* null. 
   void IntersectDemo()
   {
      Console::WriteLine( "\nIntersect demo." );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp1 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp2 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ isfp3 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ t = dynamic_cast<IsolatedStorageFilePermission^>(isfp0->Intersect(
 isfp1 ));
      if ( true == t->IsUnrestricted() )
      {
         Console::WriteLine( "The intersection of two PermissionState.Unrestricted
 permissions is unrestricted." );
      }
      else
      {
         Console::WriteLine( "Intersect demo failed because the intersection
 of two unrestricted permissions "
         "\n\tshould be unrestricted." );
      }

      t = dynamic_cast<IsolatedStorageFilePermission^>(isfp0->Intersect(
 isfp2 ));
      if ( false == t->IsUnrestricted()
 )
      {
         Console::WriteLine( "The intersection of a PermissionState.Unrestricted
 and "
         "\n\tPermissionState.None permission is not unrestricted." );
      }
      else
      {
         Console::WriteLine( "Intersect demo failed because the intersection
 of a unrestricted and "
         "\n\tnone permission should be none." );
      }

      
      // The permission set that comes back from this intersection is
 null.
      t = dynamic_cast<IsolatedStorageFilePermission^>(isfp2->Intersect(
 isfp3 ));
      if ( nullptr == t )
      {
         Console::WriteLine( "The intersection of two PermissionState.None permissions
 is null." );
      }
      else
      {
         Console::WriteLine( "Intersect failed because the intersection of two
 PermissionState.None permissions "
         "\n\tshould be null." );
      }
   }


   // UnionDemo demonstrates the Union method.
   // Union creates a permission that is the union of the current permission
 and the specified permission.
   // Note: The union of two PermissionState.None permissions is *NOT*
 null.
   void UnionDemo()
   {
      Console::WriteLine( "\nUnion demo." );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp1 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp2 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ isfp3 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ t = dynamic_cast<IsolatedStorageFilePermission^>(isfp0->Union(
 isfp1 ));
      if ( true == t->IsUnrestricted() )
      {
         Console::WriteLine( "The union of two PermissionState.Unrestricted
 permissions is unrestricted." );
      }
      else
      {
         Console::WriteLine( "Union demo failed because the union of two PermissionState.Unrestricted
 permissions "
         "\n\tshould be unrestricted" );
      }

      t = dynamic_cast<IsolatedStorageFilePermission^>(isfp0->Union( isfp2
 ));
      if ( true == t->IsUnrestricted() )
      {
         Console::WriteLine( "The union of a PermissionState.Unrestricted and
 a PermissionState.None "
         "\n\tpermission is unrestricted." );
      }
      else
      {
         Console::WriteLine( "Union demo failed because the union of a PermissionState.Unrestricted
 and a "
         "\n\tPermissionState.None permission should be unrestricted."
 );
      }

      t = dynamic_cast<IsolatedStorageFilePermission^>(isfp2->Union( isfp3
 ));
      if ( nullptr != t )
      {
         Console::WriteLine( "The union of two PermissionState.None permissions
 is none." );
      }
      else
      {
         Console::WriteLine( "Union failed because the union of two PermissionState.None
 permissions should not be null." );
         Console::WriteLine( t );
      }
   }


   // ToStringDemo demonstrates the ToString method.
   // ToString creates and returns a string representation of the current
 permission object.
   void ToStringDemo()
   {
      Console::WriteLine( "\nToString demo." );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      String^ PermString = isfp0->ToString();
      array<String^>^PermStringParts = {"class="
,"mscorlib","Version=","Culture=","PublicKeyToken="
,"version=","Unrestricted="};
      System::Collections::IEnumerator^ myEnum = PermStringParts->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         String^ part = safe_cast<String^>(myEnum->Current);
         if ( PermString->IndexOf( part ) >= 0 )
         {
            Console::WriteLine( "{0} found in the string.",
 part );
         }
         else
         {
            Console::WriteLine( "ToString demo failed because [{0}] was not
 found.", part );
         }
      }
   }


   // Demand_Deny demonstrates Demand and Deny.
   // Demand forces a SecurityException at run time if all callers higher
 in the call stack 
   // have not been granted the permission specified by the current
 instance.
   // Deny prevents callers higher in the call stack from using the
 code that calls this method to 
   // access the resource specified by the current instance.
   void Demand_DenyDemo()
   {
      Console::WriteLine( "\nDemand_Deny demo." );
      Console::WriteLine( "Denying a permission with PermissionState.Unrestricted."
 );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      isfp0->Deny();
      try
      {
         Console::WriteLine( "Denying permission a second time." );
         isfp0->Deny();
      }
      catch ( SecurityException^ ) 
      {
         Console::WriteLine( "SecurityException was thrown as expected."
 );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( String::Format( "Demand_Deny demo failed because
 an unexpected exception was thrown"
         "\n\twhen making a second call to Deny()\r\n{0}", e ) );
      }

      Console::WriteLine( "Reverting the deny." );
      IsolatedStorageFilePermission::RevertDeny();
      if ( 0 != DoDemand() )
      {
         Console::WriteLine( "Demand_Deny demo failed because an unexpected
 exception was thrown during a demand." );
      }

      isfp0->Deny();
      if ( 1 != DoDemand() )
      {
         Console::WriteLine( "Demand_Deny demo failed because the expected SecurityException
 was not thrown during a demand." );
      }

      IsolatedStorageFilePermission::RevertDeny();
      if ( 0 != DoDemand() )
      {
         Console::WriteLine( "Demand_Deny demo failed because an unexpected
 exception was thrown during a demand." );
      }
   }


   // PermitOnly demonstrates the PermitOnly method.
   // PermitOnly prevents callers higher in the call stack from using
 the code that calls this method to 
   // access all resources except for the resource specified by the
 current instance.
   void PermitOnlyDemo()
   {
      Console::WriteLine( "\nPermitOnly demo." );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      isfp0->Demand();
      isfp0->PermitOnly();
      try
      {
         isfp0->PermitOnly();
      }
      catch ( SecurityException^ ) 
      {
         Console::WriteLine( "The second call to PermitOnly caused an exception
 as expected." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( String::Format( "PermitOnly demo failed because
 an unexpected exception was thrown"
         "\n\twhen making a second call to PermitOnly()\r\n{0}", e ) );
      }

      IsolatedStorageFilePermission::RevertPermitOnly();
      if ( 0 != DemandUI() )
      {
         Console::WriteLine( "PermitOnly demo failed because an exception was
 thrown during a demand for UI permissions." );
         Console::WriteLine( "We weren't expecting this."
 );
      }

      isfp0->PermitOnly();
      if ( 1 != DemandUI() )
      {
         Console::WriteLine( "PermitOnly demo failed because a SecurityException
 was not thrown, "
         "\n\tduring a demand for UI permissions.  A SecurityException
 was expected." );
      }

      IsolatedStorageFilePermission::RevertPermitOnly();
      if ( 0 != DoDemand() )
      {
         Console::WriteLine( "PermitOnly failed because an exception was thrown
 during a demand for UI permissions." );
         Console::WriteLine( "We weren't expecting this."
 );
      }
   }


   // UserQuota_UsageDemo demonstrates UserQuota and UsageAllowed properties.
   // UserQuota gets or sets the quota on the overall size of each user's
 total store.  
   // This property is inherited from IsolatedStoragePermission.UserQuota.
   // UsageAllowed gets or sets the type of isolated storage containment
 allowed.  
   // This property is inherited from IsolatedStoragePermission.UsageAllowed.
   // Note  You can set UsageAllowed to None, but you cannot set UserQuota
 to 0.
   // Also note that trying to set UsageAllowed or UserQuota to values
 that are currently set
   // will throw an exception.  

   [method:IsolatedStorageFilePermissionAttribute(SecurityAction::Deny,UsageAllowed=IsolatedStorageContainment::DomainIsolationByRoamingUser
,UserQuota=100)]
   void UserQuota_UsageDemo()
   {
      Console::WriteLine( "\nUserQuota_Usage demo." );
      bool returnValue = false;
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      Console::WriteLine( "Checking UsageAllowed for IsolatedStorageContainment.None"
 );
      returnValue = UsageAllowed( isfp0, IsolatedStorageContainment::None, false
 );
      if (  !returnValue )
            Console::WriteLine( "IsolatedStorageContainment.None demo failed"
 );

      Console::WriteLine( "Checking UsageAllowed for IsolatedStorageContainment.DomainIsolationByRoamingUser."
 );
      returnValue = UsageAllowed( isfp0, IsolatedStorageContainment::DomainIsolationByRoamingUser,
 true );
      if (  !returnValue )
            Console::WriteLine( "IsolatedStorageContainment.DomainIsolationByRoamingUser
 failed" );

      Console::WriteLine( "Checking UsageAllowed for IsolatedStorageContainment.AssemblyIsolationByUser."
 );
      returnValue = UsageAllowed( isfp0, IsolatedStorageContainment::AssemblyIsolationByUser,
 true );
      if (  !returnValue )
            Console::WriteLine( "IsolatedStorageContainment.AssemblyIsolationByUse
 failed" );

      Console::WriteLine( "Requesting UserQuota of 0." );
      returnValue = UserQuota( isfp0, 0, true );
      if (  !returnValue )
            Console::WriteLine( "UserQuota 0 failed" );

      Console::WriteLine( "Requesting UserQuota of 100." );
      returnValue = UserQuota( isfp0, 100, true );
      if (  !returnValue )
            Console::WriteLine( "UserQuota 100 failed" );

      Console::WriteLine( "Requesting UserQuota of -2147483648." );
      returnValue = UserQuota( isfp0, Int32::MinValue, true );
      if (  !returnValue )
            Console::WriteLine( "UserQuota -214748364 failed" );
   }


   // IsSubsetOfDemo demonstrates the IsSubsetOf method.
   // IsSubsetOf determines whether the current permission is a subset
 of the specified permission.
   void IsSubsetOfDemo()
   {
      Console::WriteLine( "\nIsSubsetOf demo." );
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ isfp1 = gcnew IsolatedStorageFilePermission(
 PermissionState::None );
      IsolatedStorageFilePermission^ isfp2 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      IsolatedStorageFilePermission^ isfp3 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      if ( isfp0->IsSubsetOf( isfp1 ) )
      {
         Console::WriteLine( "PermissionState.None is a subset of PermissionState.None."
 );
      }
      else
      {
         Console::WriteLine( "IsSubsetOfDemo failed: PermissionState.None should
 be a subset of PermissionState.None" );
      }

      if ( isfp0->IsSubsetOf( isfp2 ) )
      {
         Console::WriteLine( "PermissionState.None is a subset of PermissionState.Unrestricted."
 );
      }
      else
      {
         Console::WriteLine( "IsSubsetOfDemo failed: PermissionState.None should
 be a subset of PermissionState.Unrestricted" );
      }

      if (  !isfp2->IsSubsetOf( isfp0 ) )
      {
         Console::WriteLine( "PermissionState.Unrestricted is not a subset of
 PermissionState.None." );
      }
      else
      {
         Console::WriteLine( "IsSubsetOfDemo failed: PermissionState.Unrestricted
 should not be a subset "
         "\n\tof PermissionState.None" );
      }

      if ( isfp2->IsSubsetOf( isfp3 ) )
      {
         Console::WriteLine( "PermissionState.Unrestricted is a subset of PermissionState.Unrestricted."
 );
      }
      else
      {
         Console::WriteLine( "IsSubsetOfDemo failed: Permissionstate.Unrestricted
 should be a subset of "
         "\n\tPermissionState.Unrestricted" );
      }
   }


   // **********************************************************************
   // The following methods are simple helper functions.
   // **********************************************************************
   // **********************************************************************
   // UserQuota
   // Sets UserQuota to the value that was passed in.
   //
   bool UserQuota( IsolatedStorageFilePermission^ isfp, int
 user_quota, bool exception_expected )
   {
      bool ExceptionCaught = false;
      isfp->UserQuota = user_quota;
      try
      {
         isfp->Demand();
      }
      catch ( Exception^ e ) 
      {
         ExceptionCaught = true;
         if (  !exception_expected )
         {
            Console::WriteLine( "An unexpected exception was thrown when setting
 UserQuota value [{0}]", user_quota );
            Console::WriteLine( "Exception: \r\n{0}", e );
         }
      }

      if ( ( !ExceptionCaught) && exception_expected )
      {
         Console::WriteLine( "An expected exception not thrown when setting
 UserQuota value [{0}]", user_quota );
      }

      return true;
   }


   // **********************************************************************
   // UsageAllowed
   // This method sets UsageAllowed to the value that was passed in.
   //
   bool UsageAllowed( IsolatedStorageFilePermission^ isfp, IsolatedStorageContainment
 isc, bool exception_expected )
   {
      bool ExceptionCaught = false;
      isfp->UsageAllowed = isc;
      try
      {
         isfp->Demand();
      }
      catch ( Exception^ e ) 
      {
         ExceptionCaught = true;
         if (  !exception_expected )
         {
            Console::WriteLine( "An unexpected exception was thrown when setting
 IsolatedStorageContainment value [{0}]", isc );
            Console::WriteLine( "Exception: \r\n{0}", e );
         }
      }

      if ( ( !ExceptionCaught) && exception_expected )
      {
         Console::WriteLine( "An expected exception was not thrown when setting
 IsolatedStorageContainment value [{0}]", isc );
      }

      return true;
   }


   // **********************************************************************
   // DoDemand()
   // This method demands an IsolatedStorageFilePermission.
   int DoDemand()
   {
      int ReturnValue = 0;
      IsolatedStorageFilePermission^ isfp0 = gcnew IsolatedStorageFilePermission(
 PermissionState::Unrestricted );
      try
      {
         isfp0->Demand();
      }
      catch ( SecurityException^ ) 
      {
         ReturnValue = 1;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "An unexpected exception was thrown in
 DoDemand\r\n{0}", e );
         ReturnValue = -1;
      }

      return ReturnValue;
   }


   // **********************************************************************
   // DemandUI()
   // This method demands a UIPermission
   // Returns:
   //    0 if the demand was successful.
   //    1 if a SecurityException was thrown.
   //    -1 if an unexpected exception was thrown.
   //
   int DemandUI()
   {
      int ReturnValue = 0;
      UIPermission^ MyPermission = gcnew UIPermission( PermissionState::Unrestricted
 );
      try
      {
         MyPermission->Demand();
      }
      catch ( SecurityException^ ) 
      {
         ReturnValue = 1;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "An unexpected exception was thrown in
 DemandUI\r\n{0}", e );
      }

      return ReturnValue;
   }

};

int main()
{
   Demo^ MyDemo = gcnew Demo;
   MyDemo->Run();
   return 0;
}

import System .* ;
import System.Security .* ;
import System.IO .* ;
import System.IO.IsolatedStorage .* ;
import System.Security.Permissions .* ;
import System.Diagnostics .* ;

public class Demo
{
    // Main method.
    public void Run()
    {
        try {
            Copy_EqualsDemo();
            To_FromXmlDemo();
            GetTypeDemo();
            IntersectDemo();
            UnionDemo();
            ToStringDemo();
            Demand_DenyDemo();
            PermitOnlyDemo();
            UserQuota_UsageDemo();
            IsSubsetOfDemo();
            IsUnrestrictedDemo();
        }
        catch (System.Exception e) {
            Console.WriteLine(("\r\n\nThe demo failed due to an " 
                + "unexpected exception\r\n" + e.ToString()));
        }
    } //Run

    // IsUnrestrictedDemo demonstrates the 
    // IsolatedStorageFilePermission.IsUnrestricted method.
    // IsUnrestrictedDemo displays a comment indicating whether 
    // the current permission is unrestricted.
    private void IsUnrestrictedDemo()
    {
        Console.WriteLine("IsUnrestricted demo.");
        try {
            IsolatedStorageFilePermission isfp = 
                new IsolatedStorageFilePermission(PermissionState.Unrestricted);
            isfp.Demand(); // The permission should be unrestricted.
            Console.WriteLine("Created and demanded the " 
                + "IsolatedStorageFilePermission(PermissionState." 
                + "Unrestricted)permission.");
            if (true != isfp.IsUnrestricted())
 {
                Console.WriteLine("IsUnrestricted demo failed. " 
                    + "The IsUnrestricted property value should be 'true'");
            }
            isfp = new IsolatedStorageFilePermission(PermissionState.None);
            isfp.Demand(); // The permission should not be unrestricted.
            Console.WriteLine("Created and demanded the " 
                + "IsolatedStorageFilePermission(PermissionState.None)"
                + "permission.");
            if (false != isfp.IsUnrestricted())
 {
                Console.WriteLine("IsUnrestricted demo failed. The " 
                    + "IsUnrestricted property value should be 'false'");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine(("Unexpected exception: " + e.get_Message()));
        }
    } //IsUnrestrictedDemo   

    // Copy_EqualsDemo demonstrates the Copy and Equals methods.
    // Copy creates and returns an identical copy of the current permission.
    // Equals compares two permissions and determines whether they are
 equal.
    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   

    // To_FromXmlDemo demonstrates ToXml and FromXml.
    // ToXml creates an XML encoding of the permission and its current
 state.
    // FromXml reconstructs a permission with a specified state from
 
    // an XML encoding.
    private void To_FromXmlDemo()
    {
        Console.WriteLine("\nTo_FromXML demo.");
        IsolatedStorageFilePermission firstPermission = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        Console.WriteLine(("First permission: " + firstPermission.ToString()));
        SecurityElement se = firstPermission.ToXml();
        IsolatedStorageFilePermission secondPermission = 
            new IsolatedStorageFilePermission(PermissionState.None);
        Console.WriteLine(("Second permission: " 
            + secondPermission.ToString()));
        secondPermission.FromXml(se);
        IsolatedStorageFilePermission thirdPermission = 
            ((IsolatedStorageFilePermission)
            (secondPermission.Intersect(firstPermission)));
        Console.WriteLine(("Intersection of first permission and " 
            + "second permission: " + thirdPermission.ToString()));

        try {
            if (false == thirdPermission.IsUnrestricted())
 {
                Console.WriteLine("To_FromXml demo failed: The ToXml, "
 
                    + "FromXml roundtrip did not succeed.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("To_FromXml demo failed: An exception " 
                + "was thrown when checking the intersection");
            Console.WriteLine("of the permissions after the XML roundtrip.");
            Console.WriteLine(e.ToString());
            Console.WriteLine(e.ToString());
        }
    } //To_FromXmlDemo   

    // GetType demonstrates the GetType method.
    // This method returns the type of the current instance.
    private void GetTypeDemo()
    {
        Console.WriteLine("\nGetType demo.");
        IsolatedStorageFilePermission isfp = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        if (0 != isfp.GetType().toString().CompareTo(
            "System.Security.Permissions.IsolatedStorageFilePermission"))
 {
            Console.WriteLine(("GetType returned the wrong value: " 
            + isfp.GetType().toString()));
        }
        else {
            Console.WriteLine(("GetType returned: " 
                + isfp.GetType().toString()));
        }
    } //GetTypeDemo   

    // IntersectDemo demonstrates the Intersect method.
    // CIntersect creates and returns a permission that is the intersection
 
    // of the current permission and the specified permission.
    // Note The intersection of two PermissionState.None permissions
 *IS* null.
    private void IntersectDemo()
    {
        Console.WriteLine("\nIntersect demo.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp2 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp3 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission t = 
            ((IsolatedStorageFilePermission)(isfp0.Intersect(isfp1)));
        if (true == t.IsUnrestricted()) {
            Console.WriteLine("The intersection of two " 
                + "PermissionState.Unrestricted permissions is unrestricted.");
        }
        else {
            Console.WriteLine(("Intersect demo failed because the " 
                + "intersection of two unrestricted permissions " 
                + "\n\tshould be unrestricted."));
        }
        t = ((IsolatedStorageFilePermission)(isfp0.Intersect(isfp2)));
        if (false == t.IsUnrestricted()) {
            Console.WriteLine(("The intersection of a " 
                + "PermissionState.Unrestricted and " 
                + "\n\tPermissionState.None permission is not unrestricted."));
        }
        else {
            Console.WriteLine(("Intersect demo failed because the " 
                + "intersection of a unrestricted and " 
                + "\n\tnone permission should be none."));
        }

        // The permission set that comes back from this intersection
 is null.
        t = ((IsolatedStorageFilePermission)(isfp2.Intersect(isfp3)));
        if (null == t) {
            Console.WriteLine("The intersection of two " 
                + "PermissionState.None permissions is null.");
        }
        else {
            Console.WriteLine(("Intersect failed because the " 
                + "intersection of two PermissionState.None permissions "
 
                + "\n\tshould be null."));
        }
    } //IntersectDemo   

    // UnionDemo demonstrates the Union method.
    // Union creates a permission that is the union of the current 
    // permission and the specified permission.
    // Note: The union of two PermissionState.None permissions is *NOT*
 null.
    private void UnionDemo()
    {
        Console.WriteLine("\nUnion demo.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp1 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp2 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp3 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission t = 
            ((IsolatedStorageFilePermission)(isfp0.Union(isfp1)));

        if (true == t.IsUnrestricted()) {
            Console.WriteLine("The union of two " 
                + "PermissionState.Unrestricted permissions is unrestricted.");
        }
        else {
            Console.WriteLine(("Union demo failed because the union " 
                + "of two PermissionState.Unrestricted permissions " 
                + "\n\tshould be unrestricted"));
        }
        t = ((IsolatedStorageFilePermission)(isfp0.Union(isfp2)));
        if (true == t.IsUnrestricted()) {
            Console.WriteLine(("The union of a PermissionState.Unrestricted
 " 
                + "and a PermissionState.None " 
                + "\n\tpermission is unrestricted."));
        }
        else {
            Console.WriteLine(("Union demo failed because the union of a "
 
                + "PermissionState.Unrestricted and a " 
                + "\n\tPermissionState.None permission should be "
                + "unrestricted."));
        }
        t = ((IsolatedStorageFilePermission)(isfp2.Union(isfp3)));
        if (null != t) {
            Console.WriteLine("The union of two PermissionState.None "
 
                + "permissions is none.");
        }
        else {
            Console.WriteLine("Union failed because the union of two "
 
                + "PermissionState.None permissions should not be null.");
            Console.WriteLine(t.ToString());
        }
    } //UnionDemo   

    // ToStringDemo demonstrates the ToString method.
    // ToString creates and returns a string representation of the current
 
    // permission object.
    private void ToStringDemo()
    {
        Console.WriteLine("\nToString demo.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        String permString = isfp0.ToString();
        String permStringParts[] = {"class=", "mscorlib",
 "Version=", 
            "Culture=", "PublicKeyToken=", "version=",
 "Unrestricted="};

        for (int iCtr = 0; iCtr < permStringParts.length;
 iCtr++) {
            String part = permStringParts[iCtr];
            if (permString.IndexOf(part) >= 0) {
                Console.WriteLine((part + " found in the
 string."));
            }
            else {
                Console.WriteLine("ToString demo failed because [{0}] "
 
                    + "was not found.", part);
            }
        }
    } //ToStringDemo    

    // Demand_Deny demonstrates Demand and Deny.
    // Demand forces a SecurityException at run time if all callers
 higher 
    // in the call stack have not been granted the permission specified
 
    // by the current instance.
    // Deny prevents callers higher in the call stack from using the
 code 
    // that calls this method to
    // access the resource specified by the current instance.
    private void Demand_DenyDemo()
    {
        Console.WriteLine("\nDemand_Deny demo.");
        Console.WriteLine("Denying a permission with " 
            + "PermissionState.Unrestricted.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        isfp0.Deny();

        try {
            Console.WriteLine("Denying permission a second time.");
            isfp0.Deny();
        }
        catch (SecurityException exp) {
            Console.WriteLine("SecurityException was thrown as expected.");
        }
        catch (System.Exception e) {
            Console.WriteLine(("Demand_Deny demo failed because an " 
                + "unexpected exception was thrown" 
                + "\n\twhen making a second call to Deny()\r\n" 
                + e.ToString()));
        }
        Console.WriteLine("Reverting the deny.");
        IsolatedStorageFilePermission.RevertDeny();
        if (0 != DoDemand()) {
            Console.WriteLine("Demand_Deny demo failed because an " 
                + "unexpected exception was thrown during a demand.");
        }
        isfp0.Deny();
        if (1 != DoDemand()) {
            Console.WriteLine("Demand_Deny demo failed because the " 
                + "expected SecurityException was not thrown during a demand.");
        }
        IsolatedStorageFilePermission.RevertDeny();
        if (0 != DoDemand()) {
            Console.WriteLine("Demand_Deny demo failed because an " 
                + "unexpected exception was thrown during a demand.");
        }
    } //Demand_DenyDemo   

    // PermitOnly demonstrates the PermitOnly method.
    // PermitOnly prevents callers higher in the call stack from using
 the 
    // code that calls this method to access all resources except for
 the 
    // resource specified by the current instance.
    private void PermitOnlyDemo()
    {
        Console.WriteLine("\nPermitOnly demo.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        isfp0.Demand();
        isfp0.PermitOnly();

        try {
            isfp0.PermitOnly();
        }
        catch (SecurityException exp) {
            Console.WriteLine("The second call to PermitOnly caused an "
 
                + "exception as expected.");
        }
        catch (System.Exception e) {
            Console.WriteLine(("PermitOnly demo failed because an " 
                + "unexpected exception was thrown" 
                + "\n\twhen making a second call to PermitOnly()\r\n" 
                + e.ToString()));
        }
        IsolatedStorageFilePermission.RevertPermitOnly();
        if (0 != DemandUI()) {
            Console.WriteLine("PermitOnly demo failed because an " 
                + "exception was thrown during a demand for
 UI permissions.");
            Console.WriteLine("We weren't expecting this.");
        }
        isfp0.PermitOnly();
        if (1 != DemandUI()) {
            Console.WriteLine(("PermitOnly demo failed because a " 
                + "SecurityException was not thrown, " 
                + "\n\tduring a demand for UI permissions.
 " 
                + "A SecurityException was expected."));
        }
        IsolatedStorageFilePermission.RevertPermitOnly();
        if (0 != DoDemand()) {
            Console.WriteLine("PermitOnly failed because an exception "
 
                + "was thrown during a demand for UI permissions.");
            Console.WriteLine("We weren't expecting this.");
        }
    } //PermitOnlyDemo   

    // UserQuota_UsageDemo demonstrates UserQuota and UsageAllowed properties.
    // UserQuota gets or sets the quota on the overall size of each
 user's 
    // total store. This property is inherited from 
    // IsolatedStoragePermission.UserQuota. UsageAllowed gets or sets
 the 
    // type of isolated storage containment allowed. This property is
 inherited 
    // from IsolatedStoragePermission.UsageAllowed. Note You can set
 
    // UsageAllowed to None, but you cannot set UserQuota to 0. Also
 note that 
    // trying to set UsageAllowed or UserQuota to values that are currently
 set 
    // will throw an exception.
    /** @attribute.method IsolatedStorageFilePermissionAttribute(
        SecurityAction.Deny, 
        UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser, 
        UserQuota = 100)
     */
    private void UserQuota_UsageDemo()
    {
        Console.WriteLine("\nUserQuota_Usage demo.");
        boolean returnValue = false;
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        Console.WriteLine(
            "Checking UsageAllowed for IsolatedStorageContainment.None");
        returnValue = UsageAllowed(isfp0, IsolatedStorageContainment.None, 
            false);
        if (!(returnValue)) {
            Console.WriteLine("IsolatedStorageContainment.None demo failed");
        }
        Console.WriteLine("Checking UsageAllowed for "
 
            + "IsolatedStorageContainment.DomainIsolationByRoamingUser.");
        returnValue = UsageAllowed(isfp0, 
            IsolatedStorageContainment.DomainIsolationByRoamingUser, true);
        if (!(returnValue)) {
            Console.WriteLine("IsolatedStorageContainment." 
                + "DomainIsolationByRoamingUser failed");
        }
        Console.WriteLine("Checking UsageAllowed for "
 
            + "IsolatedStorageContainment.AssemblyIsolationByUser.");
        returnValue = UsageAllowed(isfp0, 
            IsolatedStorageContainment.AssemblyIsolationByUser, true);
        if (!(returnValue)) {
            Console.WriteLine(
                "IsolatedStorageContainment.AssemblyIsolationByUse failed");
        }
        Console.WriteLine("Requesting UserQuota of 0.");
        returnValue = UserQuota(isfp0, 0, true);
        if (!(returnValue)) {
            Console.WriteLine("UserQuota 0 failed");
        }
        Console.WriteLine("Requesting UserQuota of 100.");
        returnValue = UserQuota(isfp0, 100, true);
        if (!(returnValue)) {
            Console.WriteLine("UserQuota 100 failed");
        }
        Console.WriteLine("Requesting UserQuota of -2147483648.");
        returnValue = UserQuota(isfp0, -2147483648, true);
        if (!(returnValue)) {
            Console.WriteLine("UserQuota -214748364 failed");
        }
    } //UserQuota_UsageDemo   

    // IsSubsetOfDemo demonstrates the IsSubsetOf method.
    // IsSubsetOf determines whether the current permission is a subset
 
    // of the specified permission.
    private void IsSubsetOfDemo()
    {
        Console.WriteLine("\nIsSubsetOf demo.");
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp1 = 
            new IsolatedStorageFilePermission(PermissionState.None);
        IsolatedStorageFilePermission isfp2 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        IsolatedStorageFilePermission isfp3 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);
        if (isfp0.IsSubsetOf(isfp1)) {
            Console.WriteLine("PermissionState.None is a subset of " 
                + "PermissionState.None.");
        }
        else {
            Console.WriteLine("IsSubsetOfDemo failed: PermissionState.None "
 
                + "should be a subset of PermissionState.None");
        }
        if (isfp0.IsSubsetOf(isfp2)) {
            Console.WriteLine("PermissionState.None is a subset of " 
            + "PermissionState.Unrestricted.");
        }
        else {
            Console.WriteLine("IsSubsetOfDemo failed: PermissionState.None "
 
                + "should be a subset of PermissionState.Unrestricted");
        }
        if (!(isfp2.IsSubsetOf(isfp0))) {
            Console.WriteLine("PermissionState.Unrestricted is not " 
                + "a subset of PermissionState.None.");
        }
        else {
            Console.WriteLine(("IsSubsetOfDemo failed: PermissionState."
 
                + "Unrestricted should not be a subset " 
                + "\n\tof PermissionState.None"));
        }
        if (isfp2.IsSubsetOf(isfp3)) {
            Console.WriteLine("PermissionState.Unrestricted is a " 
                + "subset of PermissionState.Unrestricted.");
        }
        else {
            Console.WriteLine(("IsSubsetOfDemo failed: " 
                + "Permissionstate.Unrestricted should be a subset of "
 
                + "\n\tPermissionState.Unrestricted"));
        }
    } //IsSubsetOfDemo

    // **********************************************************************
    // The following methods are simple helper functions.
    // **********************************************************************
    // **********************************************************************
    // UserQuota
    // Sets UserQuota to the value that was passed in.
    //
    private boolean UserQuota(IsolatedStorageFilePermission isfp,
 
        int userQuota, boolean exceptionExpected)
    {
        boolean exceptionCaught = false;

        isfp.set_UserQuota(userQuota);
        
        try {
            isfp.Demand();
        }
        catch (System.Exception e) {
            exceptionCaught = true;
            if (!(exceptionExpected)) {
                Console.WriteLine("An unexpected exception was thrown "
 
                    + "when setting UserQuota value [{0}]", 
                    System.Convert.ToString(userQuota));
                Console.WriteLine(("Exception: \r\n" + e.ToString()));
            }
        }
        if ((!(exceptionCaught)) && exceptionExpected)
 {
            Console.WriteLine("An expected exception not thrown " 
                + "when setting UserQuota value [{0}]", 
                System.Convert.ToString(userQuota));
        }
        return true;
    } //UserQuota

    // **********************************************************************
    // UsageAllowed
    // This method sets UsageAllowed to the value that was passed in.
    //
    private boolean UsageAllowed(IsolatedStorageFilePermission
 isfp, 
        IsolatedStorageContainment isc, boolean exceptionExpected)
    {
        boolean exceptionCaught = false;

        isfp.set_UsageAllowed(isc);
        
        try {
            isfp.Demand();
        }
        catch (System.Exception e) {
            exceptionCaught = true;
            if (!(exceptionExpected)) {
                Console.WriteLine("An unexpected exception was thrown "
 
                    + "when setting IsolatedStorageContainment value [{0}]",
 
                    isc.ToString());
                Console.WriteLine(("Exception: \r\n" + e.ToString()));
            }
        }
        if (!(exceptionCaught) && exceptionExpected) {
            Console.WriteLine("An expected exception was not thrown " 
                + "when setting IsolatedStorageContainment value [{0}]",
 
                isc.ToString());
        }
        return true;
    } //UsageAllowed  

    // **********************************************************************
    // DoDemand()
    // This method demands an IsolatedStorageFilePermission.
    private int DoDemand()
    {
        int returnValue = 0;
        IsolatedStorageFilePermission isfp0 = 
            new IsolatedStorageFilePermission(PermissionState.Unrestricted);

        try {
            isfp0.Demand();
        }
        catch (SecurityException exp) {
            returnValue = 1;
        }
        catch (System.Exception e) {
            Console.WriteLine(("An unexpected exception was " 
                + "thrown in DoDemand\r\n" + e.ToString()));
            returnValue = -1;
        }
        return returnValue;
    } //DoDemand

    // **********************************************************************
    // DemandUI()
    // This method demands a UIPermission
    // Returns:
    // 0 if the demand was successful.
    // 1 if a SecurityException was thrown.
    // -1 if an unexpected exception was thrown.
    //
    private int DemandUI()
    {
        int returnValue = 0;
        UIPermission MyPermission = 
            new UIPermission(PermissionState.Unrestricted);

        try {
            MyPermission.Demand();
        }
        catch (SecurityException exp) {
            returnValue = 1;
        }
        catch (System.Exception e) {
            Console.WriteLine(("An unexpected exception was thrown " 
                + "in DemandUI\r\n" + e.ToString()));
        }
        return returnValue;
    } //DemandUI   

    public static void main(String[]
 args)
    {
        Demo myDemo = new Demo();
        myDemo.Run();
        return;
    } //main
} //Demo
継承階層継承階層
System.Object
   System.Security.CodeAccessPermission
     System.Security.Permissions.IsolatedStoragePermission
      System.Security.Permissions.IsolatedStorageFilePermission
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IsolatedStorageFilePermission メンバ
System.Security.Permissions 名前空間
IsolatedStorageFilePermissionAttribute
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageContainment 列挙
その他の技術情報
アクセス許可
アクセス許可要求

IsolatedStorageFilePermission コンストラクタ

制限されアクセス許可無制限アクセス許可いずれか指定して、IsolatedStorageFilePermission クラス新しインスタンス初期化します。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    state As PermissionState _
)
Dim state As PermissionState

Dim instance As New IsolatedStorageFilePermission(state)
public IsolatedStorageFilePermission (
    PermissionState state
)
public:
IsolatedStorageFilePermission (
    PermissionState state
)
public IsolatedStorageFilePermission (
    PermissionState state
)
public function IsolatedStorageFilePermission
 (
    state : PermissionState
)

パラメータ

state

PermissionState 値の 1 つ

例外例外
例外種類条件

ArgumentException

state パラメータが、PermissionState の有効値ではありません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IsolatedStorageFilePermission クラス
IsolatedStorageFilePermission メンバ
System.Security.Permissions 名前空間

IsolatedStorageFilePermission プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ UsageAllowed  使用できる分離ストレージ コンテインメント種類取得または設定します。 ( IsolatedStoragePermission から継承されます。)
パブリック プロパティ UserQuota  ユーザー使用する領域全体サイズ基づいてクォータ取得または設定します。 ( IsolatedStoragePermission から継承されます。)
参照参照

関連項目

IsolatedStorageFilePermission クラス
System.Security.Permissions 名前空間
IsolatedStorageFilePermissionAttribute
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageContainment 列挙

その他の技術情報

アクセス許可
アクセス許可要求

IsolatedStorageFilePermission メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Assert  アクセス許可要求によって保護されているリソースへのアクセス許可が、スタックの上位にある呼び出し元に与えられていない場合でも、呼び出しコードが、このメソッド呼び出すコード通じてリソースアクセスできるように宣言しますAssert使用すると、セキュリティ上の問題発生することがあります。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Copy オーバーライドされます現在のアクセス許可コピー作成して返します
パブリック メソッド Demand  コール スタック内の上位にあるすべての呼び出し元に現在のインスタンスによって指定されているアクセス許可与えられていない場合は、実行時に SecurityException を強制します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Deny  コール スタックの上位の呼び出し元が、このメソッド呼び出すコード使用して現在のインスタンスによって指定されるリソースアクセスできないようにします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド FromXml  XML エンコーディングから、指定した状態のアクセス許可再構築ます。 ( IsolatedStoragePermission から継承されます。)
パブリック メソッド GetHashCode  ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適した CodeAccessPermission オブジェクトハッシュ コード取得します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Intersect オーバーライドされます現在のアクセス許可指定したアクセス許可積集合を表すアクセス許可作成して返します
パブリック メソッド IsSubsetOf オーバーライドされます現在のアクセス許可が、指定したアクセス許可サブセットかどうか判断します
パブリック メソッド IsUnrestricted  現在のアクセス許可無制限かどうかを示す値を返します。 ( IsolatedStoragePermission から継承されます。)
パブリック メソッド PermitOnly  コール スタックの上位の呼び出し元が、このメソッド呼び出すコード使用して現在のインスタンスによって指定されるリソース以外のすべてのリソースアクセスできないようにします。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド RevertAll  現在のフレーム対す以前オーバーライドをすべて削除し無効にます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertAssert  現在のフレーム対す以前Assert をすべて削除し無効にます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertDeny  現在のフレーム対す以前Deny をすべて削除し無効にます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド RevertPermitOnly  現在のフレーム対す以前の PermitOnly をすべて削除し無効にます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ToString  現在のアクセス許可オブジェクト文字列形式作成して返します。 ( CodeAccessPermission から継承されます。)
パブリック メソッド ToXml オーバーライドされますアクセス許可とその現在の状態を表す XML エンコーディング作成します
パブリック メソッド Union オーバーライドされます現在のアクセス許可指定したアクセス許可和集合を表すアクセス許可作成します
参照参照

関連項目

IsolatedStorageFilePermission クラス
System.Security.Permissions 名前空間
IsolatedStorageFilePermissionAttribute
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageContainment 列挙

その他の技術情報

アクセス許可
アクセス許可要求

IsolatedStorageFilePermission メンバ

プライベート仮想ファイル システム使用できることを指定します。このクラス継承できません。

IsolatedStorageFilePermission データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド IsolatedStorageFilePermission 制限されアクセス許可無制限アクセス許可いずれか指定して、IsolatedStorageFilePermission クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ UsageAllowed  使用できる分離ストレージ コンテインメント種類取得または設定します。(IsolatedStoragePermission から継承されます。)
パブリック プロパティ UserQuota  ユーザー使用する領域全体サイズ基づいてクォータ取得または設定します。(IsolatedStoragePermission から継承されます。)
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Assert  アクセス許可要求によって保護されているリソースへのアクセス許可が、スタックの上位にある呼び出し元に与えられていない場合でも、呼び出しコードが、このメソッド呼び出すコード通じてリソースアクセスできるように宣言しますAssert使用すると、セキュリティ上の問題発生することがあります。 (CodeAccessPermission から継承されます。)
パブリック メソッド Copy オーバーライドされます現在のアクセス許可コピー作成して返します
パブリック メソッド Demand  コール スタック内の上位にあるすべての呼び出し元に現在のインスタンスによって指定されているアクセス許可与えられていない場合は、実行時に SecurityException を強制します。 (CodeAccessPermission から継承されます。)
パブリック メソッド Deny  コール スタックの上位の呼び出し元が、このメソッド呼び出すコード使用して現在のインスタンスによって指定されるリソースアクセスできないようにします。 (CodeAccessPermission から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 ( CodeAccessPermission から継承されます。)
パブリック メソッド FromXml  XML エンコーディングから、指定した状態のアクセス許可再構築ます。 (IsolatedStoragePermission から継承されます。)
パブリック メソッド GetHashCode  ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適した CodeAccessPermission オブジェクトハッシュ コード取得します。 (CodeAccessPermission から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Intersect オーバーライドされます現在のアクセス許可指定したアクセス許可積集合を表すアクセス許可作成して返します
パブリック メソッド IsSubsetOf オーバーライドされます現在のアクセス許可が、指定したアクセス許可サブセットかどうか判断します
パブリック メソッド IsUnrestricted  現在のアクセス許可無制限かどうかを示す値を返します。 (IsolatedStoragePermission から継承されます。)
パブリック メソッド PermitOnly  コール スタックの上位の呼び出し元が、このメソッド呼び出すコード使用して現在のインスタンスによって指定されるリソース以外のすべてのリソースアクセスできないようにします。 (CodeAccessPermission から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド RevertAll  現在のフレーム対す以前オーバーライドをすべて削除し無効にます。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertAssert  現在のフレーム対す以前Assert をすべて削除し無効にます。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertDeny  現在のフレーム対す以前Deny をすべて削除し無効にます。 (CodeAccessPermission から継承されます。)
パブリック メソッド RevertPermitOnly  現在のフレーム対す以前の PermitOnly をすべて削除し無効にます。 (CodeAccessPermission から継承されます。)
パブリック メソッド ToString  現在のアクセス許可オブジェクト文字列形式作成して返します。 (CodeAccessPermission から継承されます。)
パブリック メソッド ToXml オーバーライドされますアクセス許可とその現在の状態を表す XML エンコーディング作成します
パブリック メソッド Union オーバーライドされます現在のアクセス許可指定したアクセス許可和集合を表すアクセス許可作成します
参照参照

関連項目

IsolatedStorageFilePermission クラス
System.Security.Permissions 名前空間
IsolatedStorageFilePermissionAttribute
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageContainment 列挙

その他の技術情報

アクセス許可
アクセス許可要求


このページでは「.NET Framework クラス ライブラリ リファレンス」からIsolatedStorageFilePermissionを検索した結果を表示しています。
Weblioに収録されているすべての辞書からIsolatedStorageFilePermissionを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からIsolatedStorageFilePermission を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IsolatedStorageFilePermission」の関連用語

IsolatedStorageFilePermissionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IsolatedStorageFilePermissionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS