次の方法で共有


EnvironmentPermission.ToXml メソッド

アクセス許可とその現在の状態を表す XML エンコーディングを作成します。

Overrides Public Function ToXml() As SecurityElement Implements _   ISecurityEncodable.ToXml
[C#]
public override SecurityElement ToXml();
[C++]
public: SecurityElement* ToXml();
[JScript]
public override function ToXml() : SecurityElement;

戻り値

アクセス許可のステータス情報を含む XML エンコーディング。

実装

ISecurityEncodable.ToXml

使用例

 
' ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs 
' a permission with the specified state from the XML encoding. 
Private Function ToFromXmlDemo() As Boolean

    Dim returnValue As Boolean = True

    Dim env1 As String
    Dim envPerm1, envPerm2 As EnvironmentPermission

    Dim envGen1 As New EnvGenerator()
    Dim envGen2 As New EnvGenerator()

    envGen1.ResetIndex()
    While envGen1.CreateEnv(envPerm1, env1, EnvironmentPermissionAccess.Read)
        If envPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        envGen2.ResetIndex()
        Try
            envPerm2 = New EnvironmentPermission(PermissionState.None)
            envPerm2.FromXml(envPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & envPerm2.ToString() & ControlChars.Lf))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & envPerm1.ToString() & e.ToString()))
            GoTo ContinueWhile1
        End Try
ContinueWhile1:
    End While

    Return returnValue
End Function 'ToFromXmlDemo


[C#] 
// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs 
// a permission with the specified state from the XML encoding. 
    private bool ToFromXmlDemo()
    {

        bool returnValue = true;

        string env1;
        EnvironmentPermission envPerm1,envPerm2;

        EnvGenerator envGen1 = new EnvGenerator();
        EnvGenerator envGen2 = new EnvGenerator();

        envGen1.ResetIndex();
        while(envGen1.CreateEnv(out envPerm1, out env1, EnvironmentPermissionAccess.Read)) 
        {
            if(envPerm1 == null) continue;
            Console.WriteLine("********************************************************\n");
            envGen2.ResetIndex();
            try
            {            
                envPerm2= new EnvironmentPermission(PermissionState.None);
                envPerm2.FromXml(envPerm1.ToXml());
                Console.WriteLine("Result of ToFromXml = " +envPerm2.ToString() + "\n");
            
            }
            catch(Exception e) 
            {
                Console.WriteLine("ToFromXml failed :" + envPerm1.ToString() + e);
                continue;
            }
        }

        return returnValue;

    }

[C++] 
// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs
// a permission with the specified state from the XML encoding.
private:
bool ToFromXmlDemo() {

   bool returnValue = true;

   String* env1;
   EnvironmentPermission* envPerm1, *envPerm2;

   EnvGenerator* envGen1 = new EnvGenerator();
   EnvGenerator* envGen2 = new EnvGenerator();

   envGen1->ResetIndex();
   while(envGen1->CreateEnv(&envPerm1, &env1, EnvironmentPermissionAccess::Read)) {
      if (envPerm1 == 0) continue;
      Console::WriteLine(S"********************************************************\n");
      envGen2->ResetIndex();
      try {
         envPerm2 = new EnvironmentPermission(PermissionState::None);
         envPerm2->FromXml(envPerm1->ToXml());
         Console::WriteLine(S"Result of ToFromXml = {0}\n", envPerm2);

      } catch (Exception* e) {
         Console::WriteLine(S"ToFromXml failed : {0}{1}", envPerm1, e);
         continue;
      }
   }

   return returnValue;

}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

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