次の方法で共有


StrongNameIdentityPermission.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 Sn1 As String
    Dim SnIdPerm1, SnIdPerm2 As StrongNameIdentityPermission

    Dim SnGen1 As New SnGenerator()
    Dim SnGen2 As New SnGenerator()

    SnGen1.ResetIndex()
    While SnGen1.CreateSn(SnIdPerm1, Sn1)
        If SnIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" + ControlChars.Lf)
        SnGen2.ResetIndex()
        Try
            SnIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
            SnIdPerm2.FromXml(SnIdPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " + SnIdPerm2.ToString() + ControlChars.Lf))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" + SnIdPerm1.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 sn1;
            StrongNameIdentityPermission snIdPerm1,snIdPerm2;

            SnGenerator snGen1 = new SnGenerator();
            SnGenerator snGen2 = new SnGenerator();

            snGen1.ResetIndex();
            while(snGen1.CreateSn(out snIdPerm1, out sn1)) 
            {
                if(snIdPerm1 == null) continue;
                Console.WriteLine("********************************************************\n");
                snGen2.ResetIndex();
                try
                {            
                    snIdPerm2= new StrongNameIdentityPermission(PermissionState.None);
                    snIdPerm2.FromXml(snIdPerm1.ToXml());
                    Console.WriteLine("Result of ToFromXml = " +snIdPerm2.ToString() + "\n");
            
                }
                catch(Exception e) 
                {
                    Console.WriteLine("ToFromXml failed :" + snIdPerm1.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.
bool ToFromXmlDemo() {

   bool returnValue = true;

   String* sn1;
   StrongNameIdentityPermission* snIdPerm1, *snIdPerm2;

   SnGenerator* snGen1 = new SnGenerator();
   SnGenerator* snGen2 = new SnGenerator();

   snGen1->ResetIndex();
   while(snGen1->CreateSn(&snIdPerm1, &sn1)) {
      if (snIdPerm1 == 0) continue;
      Console::WriteLine(S"********************************************************\n");
      snGen2->ResetIndex();
      try {
         snIdPerm2 = new StrongNameIdentityPermission(PermissionState::None);
         snIdPerm2->FromXml(snIdPerm1->ToXml());
         Console::WriteLine(S"Result of ToFromXml = {0}\n", snIdPerm2);

      } catch (Exception* e) {
         Console::WriteLine(S"ToFromXml failed : {0}{1}", snIdPerm1, 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 ファミリ

参照

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