Click here to Skip to main content
15,890,123 members
Home / Discussions / C#
   

C#

 
Questionint? Pin
seemamltn2-Oct-07 13:08
seemamltn2-Oct-07 13:08 
AnswerRe: int? Pin
Judah Gabriel Himango2-Oct-07 13:11
sponsorJudah Gabriel Himango2-Oct-07 13:11 
AnswerRe: int? Pin
Christian Graus2-Oct-07 13:11
protectorChristian Graus2-Oct-07 13:11 
QuestionHelp: NHibernate and SysCache2 [modified] Pin
emiaj2-Oct-07 12:27
emiaj2-Oct-07 12:27 
QuestionForce XmlSerializer.Deserilize to ignore empty XML tags Pin
eggie52-Oct-07 12:12
eggie52-Oct-07 12:12 
AnswerRe: Force XmlSerializer.Deserilize to ignore empty XML tags Pin
TJoe2-Oct-07 12:39
TJoe2-Oct-07 12:39 
GeneralRe: Force XmlSerializer.Deserilize to ignore empty XML tags [modified] Pin
eggie52-Oct-07 13:49
eggie52-Oct-07 13:49 
GeneralRe: Force XmlSerializer.Deserilize to ignore empty XML tags Pin
TJoe2-Oct-07 15:16
TJoe2-Oct-07 15:16 
I'm sorry, I misunderstand what you wanted. I though you had extraneous elements (e.g. items without a matching property in your C# class) that you wanted to skip.

You could derive your own class from XmlTextReader[^]and override the Read[^] method. But that would get messy because you have to take into account elements that only have sub-elements.

The easiest way is to probably define another property that you use for serialization like so:

private Int32 myInt = 0;
[XmlIgnore]
public Int32 MyInt {
    get {
        return this.myInt;
    }
    set {
        this.myInt = value;
    }
}
  
[XmlElement("MyInt")]
public String MyIntSerialize {
    get {
        return this.MyInt.ToString();
    }
    set {
        Int32 newValue = 42; // default for blank elements
        if (!String.IsNullOrEmpty(value))
            newValue = Int32.Parse(value);
        this.myInt = newValue;
    }
}


This gets messy also because you have to double up on your properties.

Take care,
Tom

-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com

GeneralRe: Force XmlSerializer.Deserilize to ignore empty XML tags Pin
eggie52-Oct-07 15:43
eggie52-Oct-07 15:43 
QuestionCounter Pin
MasterSharp2-Oct-07 11:18
MasterSharp2-Oct-07 11:18 
AnswerRe: Counter Pin
Paul Conrad2-Oct-07 11:21
professionalPaul Conrad2-Oct-07 11:21 
GeneralRe: Counter Pin
MasterSharp2-Oct-07 11:21
MasterSharp2-Oct-07 11:21 
GeneralRe: Counter Pin
MasterSharp2-Oct-07 11:23
MasterSharp2-Oct-07 11:23 
GeneralRe: Counter Pin
Paul Conrad2-Oct-07 11:26
professionalPaul Conrad2-Oct-07 11:26 
AnswerRe: Counter Pin
Christian Graus2-Oct-07 13:10
protectorChristian Graus2-Oct-07 13:10 
QuestionIcon Pin
MasterSharp2-Oct-07 11:00
MasterSharp2-Oct-07 11:00 
AnswerRe: Icon Pin
Peter Vertes2-Oct-07 11:04
Peter Vertes2-Oct-07 11:04 
Questionplease help Pin
memaia2-Oct-07 10:46
memaia2-Oct-07 10:46 
AnswerRe: please help Pin
Dan Neely2-Oct-07 10:50
Dan Neely2-Oct-07 10:50 
AnswerRe: please help Pin
Colin Angus Mackay2-Oct-07 10:50
Colin Angus Mackay2-Oct-07 10:50 
AnswerRe: please help Pin
Paul Conrad2-Oct-07 10:50
professionalPaul Conrad2-Oct-07 10:50 
AnswerRe: please help Pin
zeeShan anSari2-Oct-07 10:50
zeeShan anSari2-Oct-07 10:50 
AnswerRe: please help Pin
Dave Kreskowiak2-Oct-07 11:04
mveDave Kreskowiak2-Oct-07 11:04 
GeneralRe: please help Pin
Paul Conrad2-Oct-07 10:52
professionalPaul Conrad2-Oct-07 10:52 
GeneralRe: please help Pin
Pete O'Hanlon2-Oct-07 10:56
mvePete O'Hanlon2-Oct-07 10:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.