2012-03-19 61 views
0

我有另一個問題(這可能不是一個編碼問題的問題),但更原則..給我一段時間。我有這個C#類,如下:設置XML序列化導致doc根

namespace SMCProcessMonitor 
{ 
    public class Config 
    {  
     [XmlElement("Recipient")] 
     public string recipient; 

     [XmlElement("Server-port")] 
     public int serverport; 

     [XmlElement("Username")] 
     public string username; 

     [XmlElement("Password")] 
     public string password; 

     [XmlElement("Program")] 
     public List<Programs> mPrograms = new List<Programs>(); 

     [Serializable] 
     [XmlRoot("Email-Config")] 
     public class Email 
     { 
      public string Recipient 
      { 
       get 
       { 
        return SMCProcessMonitor.ConfigManager.mConfigurations.recipient; 
       } 
       set 
       { 
        SMCProcessMonitor.ConfigManager.mConfigurations.recipient = value; 
       } 
      } 

      public int ServerPort 
      { 
       get 
       { 
        return SMCProcessMonitor.ConfigManager.mConfigurations.serverport; 
       } 
       set 
       { 
        SMCProcessMonitor.ConfigManager.mConfigurations.serverport = value; 
       } 
      } 
      public string Username 
      { 
       get 
       { 
        return SMCProcessMonitor.ConfigManager.mConfigurations.username; 
       } 
       set 
       { 
        SMCProcessMonitor.ConfigManager.mConfigurations.username = value; 
       } 
      } 

     public string Password { get; set; } 
    } 
} 

我可以序列化這幾乎罰款。 (我最近改變了簡單的獲取;集;如上面看到的,但是連載的時候我得到這樣的全作品;

<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <Recipient>sd</Recipient> 
    <Server-port>1234</Server-port> 
    <Username>dk</Username> 
    <Password>kdkdk</Password> 
</Config> 

基本上我想在「電子郵件設置」來包裝這些4個標記標籤。

+0

我也是剛剛纔發現自己錯過了結束配置類支架之前,我開始了emailsettings類 – 2012-03-19 17:48:35

回答

2

添加了Serializable()和XmlRoot屬性到基類:

[Serializable()] 
[XmlRoot("Email-Settings")] 
public class Config 
0

你需要創建一個EmailSettings類,它包含的4個屬性,然後進行EmailSettings類的Config類的成員的實例。