可能重复:
Serializing object with no namespaces using DataContractSerializer
当我序列化这个类的对象时:
[DataContract]
internal class Settings
{
[DataMember]
public List<string> AllowedEmails { get; set; }
}
我已将此XML作为输出:
<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns="http://schemas.datacontract.org/2004/07/Commands.Settings">
<AllowedEmails xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>asdsada</d2p1:string>
<d2p1:string>asdsada</d2p1:string>
</AllowedEmails>
</Settings>
有没有办法摆脱名称空间xmlns="http://schemas.datacontract.org/2004/07/Commands.Settings"
和xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
?
我知道我可以通过这样做删除d2p1命名空间:
public Settings()
{
[DataMember]
public AllowedEmails AllowedEmails { get; set; }
}
[CollectionDataContract]
public class AllowedEmails : List<string>
{
public AllowedEmails()
{
}
}
但可能有更优雅的解决方案?