GacMembershipCondition.ToXml 方法

定义

创建安全对象及其当前状态的 XML 编码。Creates an XML encoding of the security object and its current state.

重载

ToXml()

创建安全对象及其当前状态的 XML 编码。Creates an XML encoding of the security object and its current state.

ToXml(PolicyLevel)

使用指定的策略级别上下文创建安全对象的 XML 编码及其当前状态。Creates an XML encoding of the security object and its current state, using the specified policy level context.

ToXml()

创建安全对象及其当前状态的 XML 编码。Creates an XML encoding of the security object and its current state.

public:
 virtual System::Security::SecurityElement ^ ToXml();
public System.Security.SecurityElement ToXml ();
abstract member ToXml : unit -> System.Security.SecurityElement
override this.ToXml : unit -> System.Security.SecurityElement
Public Function ToXml () As SecurityElement

返回

SecurityElement

包含安全对象的 XML 编码(包括所有状态信息)的 SecurityElementA SecurityElement that contains the XML encoding of the security object, including any state information.

实现

示例

下面的代码示例演示方法的用法 ToXmlThe following code example shows the use of the ToXml method. 此示例是为类提供的更大示例的一部分 GacMembershipConditionThis example is part of a larger example provided for the GacMembershipCondition class.

GacMembershipCondition ^ Gac1 = gcnew GacMembershipCondition;
GacMembershipCondition ^ Gac2 = gcnew GacMembershipCondition;

// Roundtrip a GacMembershipCondition to and from an XML encoding.
Gac2->FromXml(Gac1->ToXml());
bool result = Gac2->Equals(Gac1);
if (result)
{
    Console::WriteLine("Result of ToXml() = {0}", Gac2->ToXml());
    Console::WriteLine(
        "Result of ToFromXml roundtrip = {0}", Gac2);
}
else
{
    Console::WriteLine(Gac2->ToString());
    Console::WriteLine(Gac1->ToString());
    return false;
}
GacMembershipCondition Gac1 = new GacMembershipCondition();
GacMembershipCondition Gac2 = new GacMembershipCondition();

// Roundtrip a GacMembershipCondition to and from an XML encoding.
Gac2.FromXml(Gac1.ToXml());
bool result = Gac2.Equals(Gac1);
if (result)
{
    Console.WriteLine(
        "Result of ToXml() = " + Gac2.ToXml().ToString());
    Console.WriteLine(
        "Result of ToFromXml roundtrip = " + Gac2.ToString());
}
else
{
    Console.WriteLine(Gac2.ToString());
    Console.WriteLine(Gac1.ToString());
    return false;
}
Dim Gac1 As New GacMembershipCondition
Dim Gac2 As New GacMembershipCondition

' Roundtrip a GacMembershipCondition to and from an XML encoding.
Gac2.FromXml(Gac1.ToXml())
Dim result As Boolean = Gac2.Equals(Gac1)
If result Then
    Console.WriteLine(("Result of ToXml() = " & _ 
        Gac2.ToXml().ToString()))
    Console.WriteLine(("Result of ToFromXml roundtrip = " & _ 
        Gac2.ToString()))
Else
    Console.WriteLine(Gac2.ToString())
    Console.WriteLine(Gac1.ToString())
    Return False
End If

注解

使用 FromXml 方法可从还原状态信息 SecurityElementUse the FromXml method to restore the state information from a SecurityElement.

适用于

ToXml(PolicyLevel)

使用指定的策略级别上下文创建安全对象的 XML 编码及其当前状态。Creates an XML encoding of the security object and its current state, using the specified policy level context.

public:
 virtual System::Security::SecurityElement ^ ToXml(System::Security::Policy::PolicyLevel ^ level);
public System.Security.SecurityElement ToXml (System.Security.Policy.PolicyLevel level);
abstract member ToXml : System.Security.Policy.PolicyLevel -> System.Security.SecurityElement
override this.ToXml : System.Security.Policy.PolicyLevel -> System.Security.SecurityElement
Public Function ToXml (level As PolicyLevel) As SecurityElement

参数

level
PolicyLevel

用于解析 PolicyLevel 引用的 NamedPermissionSet 上下文。The PolicyLevel context for resolving NamedPermissionSet references.

返回

SecurityElement

包含安全对象的 XML 编码(包括所有状态信息)的 SecurityElementA SecurityElement that contains the XML encoding of the security object, including any state information.

实现

示例

下面的代码示例演示方法的用法 ToXmlThe following code example shows the use of the ToXml method. 此示例是为类提供的更大示例的一部分 GacMembershipConditionThis example is part of a larger example provided for the GacMembershipCondition class.

GacMembershipCondition ^ Gac3 = gcnew GacMembershipCondition;
GacMembershipCondition ^ Gac4 = gcnew GacMembershipCondition;
IEnumerator^ policyEnumerator = SecurityManager::PolicyHierarchy();
while (policyEnumerator->MoveNext())
{
    PolicyLevel^ currentLevel = 
        dynamic_cast<PolicyLevel^>(policyEnumerator->Current);
    if (currentLevel->Label->Equals("Machine"))
    {
        Console::WriteLine("Result of ToXml(level) = {0}", 
            Gac3->ToXml(currentLevel));
        Gac4->FromXml(Gac3->ToXml(), currentLevel);
        Console::WriteLine(
            "Result of FromXml(element, level) = {0}", Gac4);
    }
}
GacMembershipCondition Gac3 = new GacMembershipCondition();
GacMembershipCondition Gac4 = new GacMembershipCondition();
IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
while (policyEnumerator.MoveNext())
{
    PolicyLevel currentLevel = 
        (PolicyLevel)policyEnumerator.Current;
    if (currentLevel.Label == "Machine")
    {
        Console.WriteLine("Result of ToXml(level) = " + 
            Gac3.ToXml(currentLevel));
        Gac4.FromXml(Gac3.ToXml(), currentLevel);
        Console.WriteLine("Result of FromXml(element, level) = " + 
            Gac4.ToString());
    }
}
Dim Gac3 As New GacMembershipCondition
Dim Gac4 As New GacMembershipCondition
Dim policyEnumerator As IEnumerator = _
    SecurityManager.PolicyHierarchy()
While policyEnumerator.MoveNext()
    Dim currentLevel As PolicyLevel = _
        CType(policyEnumerator.Current, PolicyLevel)
    If currentLevel.Label = "Machine" Then
        Console.WriteLine(("Result of ToXml(level) = " & _
            Gac3.ToXml(currentLevel).ToString()))
        Gac4.FromXml(Gac3.ToXml(), currentLevel)
        Console.WriteLine(("Result of FromXml(element, level) = " _
            & Gac4.ToString()))
    End If
End While

注解

为解析命名权限集引用提供了策略级别上下文。The policy level context is provided for resolution of named permission set references. 例如,代码组使用策略级别来查找命名的权限集。For example, code groups use policy level to find named permission sets.

适用于