CodeAccessPermission.FromXml(SecurityElement) 方法

定义

当在派生类中替代时,用 XML 编码重新构造具有指定状态的安全对象。

public:
 abstract void FromXml(System::Security::SecurityElement ^ elem);
public abstract void FromXml (System.Security.SecurityElement elem);
abstract member FromXml : System.Security.SecurityElement -> unit
Public MustOverride Sub FromXml (elem As SecurityElement)

参数

elem
SecurityElement

用于重新构造安全对象的 XML 编码。

实现

例外

elem 参数为 null

elem 参数不包含与当前实例类型相同的实例的 XML 编码。

- 或 -

不支持 elem 参数的版本号。

示例

下面的代码示例演示 方法的 FromXml 重写。 此代码示例是为 CodeAccessPermission 类提供的一个更大示例的一部分。

public:
   virtual void FromXml( SecurityElement^ e ) override
   {
      // The following code for unrestricted permission is only included as an example for
      // permissions that allow the unrestricted state. It is of no value for this permission.
      String^ elUnrestricted = e->Attribute("Unrestricted");
      if ( nullptr != elUnrestricted )
      {
         m_Unrestricted = Boolean::Parse( elUnrestricted );
         return;
      }

      String^ elName = e->Attribute("Name");
      m_Name = elName == nullptr ? nullptr : elName;
   }
public override void FromXml(SecurityElement e)
 {
     // The following code for unrestricted permission is only included as an example for
     // permissions that allow the unrestricted state. It is of no value for this permission.
     String elUnrestricted = e.Attribute("Unrestricted");
     if (null != elUnrestricted)
     {
         m_Unrestricted = bool.Parse(elUnrestricted);
         return;
     }

     String elName = e.Attribute( "Name" );
     m_Name = elName == null ? null : elName;
 }
Public Overrides Sub FromXml(ByVal e As SecurityElement)
    ' The following code for unrestricted permission is only included as an example for
    ' permissions that allow the unrestricted state. It is of no value for this permission.
    Dim elUnrestricted As String = e.Attribute("Unrestricted")
    If Nothing <> elUnrestricted Then
        m_Unrestricted = Boolean.Parse(elUnrestricted)
        Return
    End If

    Dim elName As String = e.Attribute("Name")
    m_name = IIf(elName Is Nothing, Nothing, elName)
End Sub

注解

扩展安全对象的自定义代码需要实现 ToXmlFromXml 方法,以使对象具有安全性。

实施者说明

必须在派生类中重写此方法。

适用于