XML к вопросу о классе C#

Попробуйте модуль iso8601 ; это делает точно это.

существует несколько других опций, упомянутых на страница WorkingWithTime на Wiki python.org.

7
задан CoderDennis 15 July 2009 в 18:24
поделиться

6 ответов

Bare minimum working... looks like you are only required to add one attribute.

public class EmailConfiguration
{
    public string DataBoxID { get; set; }
    public DefaultSendToAddressCollectionClass DefaultSendToAddressCollection { get; set; }
}

public class DefaultSendToAddressCollectionClass
{
    [XmlElement]
    public string[] EmailAddress { get; set; }
}
3
ответ дан 6 December 2019 в 06:03
поделиться

Did you use VS2008's XSD?

Here's the output I got:

c:>xsd email.xml
Writing file 'c:\email.xsd'

c:>xsd email.xsd /c /edb
Writing file 'c:\email.cs'

Generates serializable output:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class EmailConfiguration : object,  System.ComponentModel.INotifyPropertyChanged {

private string dataBoxIDField;

private EmailConfigurationDefaultSendToAddressCollection[] defaultSendToAddressCollectionField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string DataBoxID {
    get {
        return this.dataBoxIDField;
    }
    set {
        this.dataBoxIDField = value;
        this.RaisePropertyChanged("DataBoxID");
    }
}
11
ответ дан 6 December 2019 в 06:03
поделиться

Использование .NET 3.5:

[XmlRoot]
public class EmailConfiguration
{
    [XmlElement]
    public string DataBoxID { get; set; }

    [XmlElement]
    public DefaultSendToAddressCollectionClass DefaultSendToAddressCollection { get; set; }
}

public class DefaultSendToAddressCollectionClass
{
    [XmlElement]
    public string[] EmailAddress { get; set; }
}
3
ответ дан 6 December 2019 в 06:03
поделиться

XSD.EXE is the tool that produces classes specifically for the purpose of XML Serialization. If it produces partial classes, that's because they work for XML Serialization. That's not what your problem is.

Try using XSD.EXE and serializing / deserializing. If you get an exception again, then please catch it and then post the results of ex.ToString().

1
ответ дан 6 December 2019 в 06:03
поделиться

Этот класс будет сериализован так, как вы хотите. Я изменил вашу пользовательскую коллекцию на список и использовал атрибут XmlArrayItem, чтобы указать, как каждый адрес электронной почты будет сериализован. Существует множество таких атрибутов, которые помогут вам точно настроить процесс сериализации.

[Serializable]
public class EmailConfiguration {
    private string dataBoxID;
    public string DataBoxID {
        get { return dataBoxID; }
        set { dataBoxID = value; }
    }

    private List<string> defaultSendToAddressCollection;

    [XmlArrayItem("EmailAddress")]
    public List<string> DefaultSendToAddressCollection {
        get { return defaultSendToAddressCollection; }
        set { defaultSendToAddressCollection = value; }
    }

    public EmailConfiguration() {
        DefaultSendToAddressCollection = new List<string>();
    }
}
1
ответ дан 6 December 2019 в 06:03
поделиться

XML serialization requires attributes. The way I've usually done it is to flag the class itself with [Serializable] and [XmlRoot], then mark up public properties with either [XmlElement], [XmlAttribute] or [NoSerialize].

What specific problem are you having?

0
ответ дан 6 December 2019 в 06:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: