c# Getting a nullable attribute to serialize to xml
by brian on Jul.23, 2009, under .NET, c#, c# coding GUI, coding, linq
It isn’t straight forward to get a nullable field to serialize. Technically it isn’t supported. But I just discovered a way today. You see null strings are supported. The idea is to ignore the real nullable property while substituting the string version as follows:
[XmlRoot("Comment")]
public class Comment
{
[XmlIgnore]
public DateTime? CommentTime { get; set; }
[XmlAttribute("CommentTime")]
public string CommentTimeStr
{
get
{
return (CommentTime.HasValue) ? CommentTime.Value.ToString() : null;
}
set
{
if (string.IsNullOrEmpty(value))
CommentTime = null;
else
CommentTime = DateTime.Parse(value);
}
}
}
Now it can be serialized.
102 comments for this entry:

August 29th, 2010 on 1:40 am
r\x3dh http://ACEHARDWAREE.INFO/tag/r\x3dh : r\x3dh…
r\x3dh…
August 29th, 2010 on 3:56 am
neuro http://zlancomepfl6u7.ANTIQUEFURNINISHING.INFO/tag/formula+white+neuro/ : formula…
neuro…
August 29th, 2010 on 3:15 pm
sheet http://wextralprb.AWESOMEBABYCLOTHES.INFO/tag/sheet+sets+pocket+sheets/ : sets…
sets…
August 29th, 2010 on 7:00 pm
California http://cmeowxar.01DODGEPARTS.US/tag/California+swimming+york/ : swimming…
California…
September 7th, 2010 on 4:38 am
Buy:Arimidex.Lumigan.Human Growth Hormone.Mega Hoodia.Nexium.Zovirax.Synthroid.Valtrex.Zyban.100% Pure Okinawan Coral Calcium.Petcam (Metacam) Oral Suspension.Prevacid.Prednisolone.Actos.Accutane.Retin-A….
November 10th, 2010 on 9:17 pm
…
BUY FASHION. TOP BRANDS: GUCCI, DOLCE&GABBANA, BURBERRY, DIESEL, ICEBERG, ROBERTO CAVALLI, EMPORIO ARMANI, VERSACE…
December 17th, 2010 on 10:18 pm
████████►BUY VIAGRA◀███████…
████████▲▲▲▲▲▲▲▲▲████████…
December 22nd, 2010 on 5:12 am
symbicort vs advair…
Buyno prescription…
December 22nd, 2010 on 11:20 am
dosage of amoxicillin for respiratory disorder…
Buygeneric drugs…
December 23rd, 2010 on 3:43 am
Cialis UK…
Buygeneric meds…
December 28th, 2010 on 4:29 pm
Aleve@official.site” rel=”nofollow”>..…
Buyit now…
December 29th, 2010 on 8:26 am
aloe@vera.gel.indicatii” rel=”nofollow”>……
Buygeneric drugs…
December 29th, 2010 on 6:18 pm
Amoxicillin@official.site” rel=”nofollow”>……
Buyno prescription…
December 30th, 2010 on 2:34 pm
avodart@dosage.now” rel=”nofollow”>..…
Buygeneric meds…
December 31st, 2010 on 6:44 am
Azor@official.site” rel=”nofollow”>……
Buygeneric pills…
December 31st, 2010 on 5:38 pm
Aricept@official.site” rel=”nofollow”>.…
Buynow…
January 1st, 2011 on 10:10 pm
Crestor@official.site” rel=”nofollow”>.…
Buywithout prescription…
January 4th, 2011 on 10:43 am
generic@viagra.sildenafil.paypal.no.prescription” rel=”nofollow”>……
Buygeneric meds…
January 5th, 2011 on 6:09 am
< a href="http://my.gardenguides.com/members/buy-Cialis? buy@Cialis.now…
Buydrugs without prescription…
January 5th, 2011 on 12:47 pm
abilify@and.sleep.issues” rel=”nofollow”>.…
Buyno prescription…
January 6th, 2011 on 2:44 am
cheap@Viagra.now” rel=”nofollow”>……
Buygeneric pills…
January 7th, 2011 on 10:06 am
Risperdal@official.site” rel=”nofollow”>..…
Buynow it…
January 21st, 2011 on 4:46 am
Zyrtec@official.site” rel=”nofollow”>.…
Buynow…
January 21st, 2011 on 5:59 am
Depakote@official.site” rel=”nofollow”>.…
Buygeneric drugs…
February 3rd, 2011 on 4:54 am
lisinopril aspirin interaction…
Buywithout prescription…
February 3rd, 2011 on 1:13 pm
Verapamil…
Buygeneric drugs…
February 4th, 2011 on 1:15 am
zyban pill…
Buywithout prescription…
February 4th, 2011 on 11:43 am
what is the shelf life of zyrtec…
Buynow it…
February 6th, 2011 on 2:46 am
alternative for warfarin medication…
Buynow…
February 6th, 2011 on 3:34 am
Zetia…
Buyno prescription…
February 6th, 2011 on 9:21 am
zantac infant…
Buyit now…
March 3rd, 2011 on 2:13 am
Zofran…
Buygeneric pills…
March 3rd, 2011 on 7:02 pm
zoloft works…
Buygeneric pills…
March 3rd, 2011 on 9:32 pm
Lexapro…
Buygeneric drugs…
March 3rd, 2011 on 11:15 pm
Vitamin E…
Buygeneric drugs…
March 6th, 2011 on 7:20 am
claritin eye drops…
Buygeneric drugs…
March 6th, 2011 on 8:59 am
Omnicef…
Buywithout prescription…
March 6th, 2011 on 8:28 pm
Orlistat…
Buyit now…
March 6th, 2011 on 8:59 pm
arthritis orlistat…
Buyno prescription…
March 7th, 2011 on 10:17 pm
Rogaine…
Buygeneric meds…
March 8th, 2011 on 5:37 am
Prozac…
Buyno prescription…
March 9th, 2011 on 1:48 am
Prozac…
Buygeneric meds…
March 9th, 2011 on 3:20 am
Seroquel…
Buygeneric drugs…
March 9th, 2011 on 1:59 pm
is overdosing on seroquel painful…
Buydrugs without prescription…
March 9th, 2011 on 3:52 pm
buy orlistat alli…
Buygeneric drugs…
March 10th, 2011 on 2:11 am
rogaine for thicker eyebrows…
Buynow…
March 10th, 2011 on 6:18 am
prozac breast feeding…
Buydrugs without prescription…
March 10th, 2011 on 11:28 am
Rogaine…
Buygeneric meds…
March 11th, 2011 on 8:15 am
Paxil…
Buygeneric drugs…
March 28th, 2011 on 9:21 am
Pyrantel@Pamoate.now” rel=”nofollow”>..…
Buygeneric pills…
March 28th, 2011 on 4:37 pm
Pulmicort@Pulmicort.Pulmicort” rel=”nofollow”>.…
Buynow it…
March 28th, 2011 on 9:33 pm
Zoloft…
Buynow it…
March 29th, 2011 on 9:25 am
Purim@Purim.Purim” rel=”nofollow”>..…
Buynow…
March 29th, 2011 on 6:40 pm
Skelaxin@Skelaxin.Skelaxin” rel=”nofollow”>..…
Buyit now…
March 30th, 2011 on 8:44 am
symbicort@official.us.website” rel=”nofollow”>……
Buygeneric drugs…
March 30th, 2011 on 5:01 pm
Cytoxan@Cytoxan.Cytoxan” rel=”nofollow”>..…
Buydrugs without prescription…
March 30th, 2011 on 6:08 pm
Seroquel@Seroquel.Seroquel” rel=”nofollow”>..…
Buynow it…
March 30th, 2011 on 7:44 pm
Provera@Provera.Provera” rel=”nofollow”>.…
Buygeneric pills…
March 30th, 2011 on 7:59 pm
risperdal@warnings.for.elderly” rel=”nofollow”>……
Buynow it…
March 31st, 2011 on 12:22 am
Coumadin@Coumadin.Coumadin” rel=”nofollow”>.…
Buyno prescription…
March 31st, 2011 on 6:08 am
Prozac@Prozac.Prozac” rel=”nofollow”>.…
Buygeneric drugs…
March 31st, 2011 on 7:02 am
Synthroid@Synthroid.Synthroid” rel=”nofollow”>.…
Buynow…
March 31st, 2011 on 8:51 am
Cipro@Cipro.Cipro” rel=”nofollow”>..…
Buygeneric meds…
March 31st, 2011 on 10:20 am
Seroquel@Seroquel.Seroquel” rel=”nofollow”>..…
Buywithout prescription…
March 31st, 2011 on 4:05 pm
Pulmicort@Pulmicort.Pulmicort” rel=”nofollow”>..…
Buygeneric meds…
March 31st, 2011 on 4:10 pm
Seroquel@Seroquel.Seroquel” rel=”nofollow”>……
Buydrugs without prescription…
April 1st, 2011 on 7:00 am
coral@calcium.ultra” rel=”nofollow”>……
Buygeneric drugs…
April 1st, 2011 on 8:09 am
buy@human.growth.hormone.product” rel=”nofollow”>……
Buygeneric drugs…
April 1st, 2011 on 5:21 pm
cms@coverage.of.pulmicort.respules.j7627” rel=”nofollow”>.…
Buygeneric pills…
April 1st, 2011 on 7:05 pm
early@childhood.purim.crafts” rel=”nofollow”>.…
Buygeneric drugs…
April 1st, 2011 on 9:29 pm
dapple@hydrocortisone.cream” rel=”nofollow”>……
Buyit now…
April 2nd, 2011 on 12:17 am
.…
Buygeneric pills…
April 2nd, 2011 on 12:07 pm
……
Buygeneric drugs…
April 2nd, 2011 on 6:08 pm
pyridium@can.cause.low.blood.sugar” rel=”nofollow”>.…
Buygeneric drugs…
April 2nd, 2011 on 8:04 pm
celexa@and.mda” rel=”nofollow”>……
Buygeneric drugs…
April 2nd, 2011 on 11:45 pm
reglan@black.box” rel=”nofollow”>……
Buydrugs without prescription…
April 3rd, 2011 on 12:33 am
cipro@causes.problems” rel=”nofollow”>.…
Buygeneric drugs…
April 3rd, 2011 on 2:23 am
claritin@helps.poison.ivy” rel=”nofollow”>……
Buydrugs without prescription…
April 3rd, 2011 on 6:03 am
buy@acai.berry.supplement” rel=”nofollow”>.…
Buyit now…
April 3rd, 2011 on 7:10 am
.…
Buywithout prescription…
April 3rd, 2011 on 8:22 am
accutane@and.ototoxicity” rel=”nofollow”>……
Buyno prescription…
April 3rd, 2011 on 10:19 am
retrovir@for.cfs” rel=”nofollow”>..…
Buygeneric meds…
April 3rd, 2011 on 7:19 pm
difference@between.medrol.and.prednisolone” rel=”nofollow”>……
Buywithout prescription…
April 4th, 2011 on 8:36 am
can@you.take.vicodin.with.prednisolone” rel=”nofollow”>.…
Buynow…
April 4th, 2011 on 9:45 am
effexor@drug.interaction” rel=”nofollow”>.…
Buygeneric pills…
April 4th, 2011 on 4:54 pm
is@prometrium.and.blood.clots” rel=”nofollow”>..…
Buywithout prescription…
April 4th, 2011 on 6:23 pm
cutting@proscar.tablets” rel=”nofollow”>.…
Buygeneric pills…
April 5th, 2011 on 1:24 am
.…
Buygeneric drugs…
April 5th, 2011 on 2:20 am
buy@online.amoxicillin” rel=”nofollow”>.…
Buywithout prescription…
April 5th, 2011 on 5:48 am
arava@institute.for.enviornmental.studies.dr.elaine.solowey” rel=”nofollow”>..…
Buynow…
April 5th, 2011 on 6:13 am
otc@nasonex.alternative” rel=”nofollow”>……
Buynow…
April 5th, 2011 on 7:27 am
gout@drugs.arcoxia” rel=”nofollow”>.…
Buygeneric pills…
April 5th, 2011 on 9:18 am
best@ay.to.take.extenze” rel=”nofollow”>……
Buyit now…
April 5th, 2011 on 10:17 am
coral@calcium.safety” rel=”nofollow”>.…
Buyit now…
April 5th, 2011 on 12:03 pm
how@well.does.nexium.cure.barretts.esophagus” rel=”nofollow”>.…
Buygeneric drugs…
April 5th, 2011 on 4:52 pm
changing@from.paxil.to.paxil.cr” rel=”nofollow”>.…
Buyno prescription…
April 5th, 2011 on 7:37 pm
plan@b.skateboards.at.target” rel=”nofollow”>.…
Buywithout prescription…
April 6th, 2011 on 1:06 am
abilify@does.it.work” rel=”nofollow”>.…
Buynow it…
April 6th, 2011 on 7:36 am
calories@and.nutrition.in.boost.nutritional.energy.drink” rel=”nofollow”>……
Buywithout prescription…
April 6th, 2011 on 12:19 pm
livingston@foot.care.bellmore” rel=”nofollow”>.…
Buyit now…
April 7th, 2011 on 2:17 am
multiple@myeloma.gleevec.clinical.trials” rel=”nofollow”>.…
Buynow it…
July 19th, 2011 on 7:45 pm
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…