共用方式為


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

備註

擴充安全性物件的自定義程式碼需要實 ToXml 作 和 FromXml 方法來讓對象成為安全性可編碼。

給實施者的注意事項

您必須在衍生類別中覆寫這個方法。

適用於