2010-06-29 40 views
2
[XmlRoot("ConfigurationRoot")] 
public class XmlDBConfiguration 
{ 
    [XmlArray("Customers")] 
    [XmlArrayItem("Customer", typeof(Customer))] 

    public ArrayList _customers; 
    private Dictionary<string, Customer> _customerDictionary;} 

是否有可能从另一个静态类或任何其他方式定义元素名称(在我的情况下它是ConfigurationRoot)?我想定义我的类将被序列化(在我的情况下,它是客户)以及。是否有可能在那里放置一个变量,并在创建实例时更改它?定义XmlRoot并用变量对其进行输入?

在此先感谢

回答

2

是的,你可以通过使用XmlSerializer构造函数,一个XmlAttributesOverrides对象做。明确支持提供您自己的XmlRootAttribute。这在MSDN Library topic中得到了很好的解释。

相关问题