c# - XmlSerializer ignores attributes -


xmlserializer ignores class attributes. i'm writing simple serializer, , used [serializable] , [nonserialized] attributes, tried use [xmlroot] , [xmlignore]. , i've noticed, although field has attribute [nonserialized] serialized.

and ignores other attributes such [xmatribute]. i've noticed it's not necessary use attributes, , can serialize class without these attributes, how can ignore fields?

my class:

[serializable] public class route {     int busnumber;     string bustype, destination;     datetime departure, arrival;     [nonserialized]datetime creationdate;     ... } 

and i'm trying serialize list<route>

private void savetoolstripmenuitem_click(object sender, eventargs e) {     stream stream = file.openwrite(environment.currentdirectory + "\\routes.xml");     xmlserializer xmlser = new xmlserializer(typeof(list<route>));     xmlser.serialize(stream, ((fileform)activemdichild).routes);     stream.close(); } 

i believe looking xmlignoreattribute. also, properties need serialized must declared public.

usage follows:

public class route {     public int busnumber;     public string bustype, destination;     public datetime departure, arrival;     [xmlignore]     public datetime creationdate;      // how ignore property     private int ignored;     [xmlignore]     public int ignored { { return ignored; } set { ignored = value; } } } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -