次の方法で共有


RegistryPermission.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 reg1 As String
    Dim regPerm1, regPerm2 As RegistryPermission

    Dim regGen1 As New regGenerator()
    Dim regGen2 As New regGenerator()

    regGen1.ResetIndex()
    While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read)
        If regPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        regGen2.ResetIndex()
        Try
            regPerm2 = New RegistryPermission(PermissionState.None)
            regPerm2.FromXml(regPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & regPerm2.ToString() & ControlChars.Lf))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & regPerm1.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 reg1;
    RegistryPermission regPerm1,regPerm2;

    RegGenerator regGen1 = new RegGenerator();
    RegGenerator regGen2 = new RegGenerator();

    regGen1.ResetIndex();
    while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) 
    {
        if(regPerm1 == null) continue;
        Console.WriteLine("********************************************************\n");
        regGen2.ResetIndex();
        try
        {            
            regPerm2= new RegistryPermission(PermissionState.None);
            regPerm2.FromXml(regPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +regPerm2.ToString() + "\n");
        
        }
        catch(Exception e) 
        {
            Console.WriteLine("ToFromXml failed :" + regPerm1.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* reg1;
    RegistryPermission* regPerm1;
    RegistryPermission* regPerm2;

    RegGenerator* regGen1 = new RegGenerator();
    RegGenerator* regGen2 = new RegGenerator();

    regGen1->ResetIndex();
    while(regGen1->CreateReg(&regPerm1, &reg1, RegistryPermissionAccess::Read)) 
    {
        if(regPerm1 == 0) continue;
        Console::WriteLine(S"********************************************************\n");
        regGen2->ResetIndex();
        try
        {            
            regPerm2= new RegistryPermission(PermissionState::None);
            regPerm2->FromXml(regPerm1->ToXml());
            Console::WriteLine(S"Result of ToFromXml = {0}\n", regPerm2);

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

参照

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