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 方法,才能讓物件成為可編碼的物件。

給實施者的注意事項

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

適用於