Friday, January 16, 2004

...in my post about Dynamic Attributes, I was specifically looking at the runtime modification of serialization attributes.  This is not exactly appropriate.  Attributes are there to add additional information to your assembly about a particular method, property, field, class, etc.  The attributes are compiled into your assembly and available through reflection.   This is very useful but not a good place to implement conditional functionality.

My solution was really not so complex.  My need was to conditionally serialize a property of a class.  Basically, under condition a, serialize PropertyA to xml and skip PropertyB.  Under condition b, serialize PropertyB to xml and skip PropertyA. 

One way to accomplish this would be to have to derivations of a common base class.  FooA and FooB inherit from base class Foo.  Each could use Attributes to mark the appropriate property [XmlIgnore].  So, in a sense, dynamic attributes, in an indirect sort of way.

The way I decided to accomplish this is pretty simple...  The class has a public method called SerializeToXml.  This method handles the serialization details for this class.  Within this method, if a check for PropertyA finds it full of data, PropertyB is copied to a temporary local variable and then PropertyA is nullified.  The class is serialized to file and then the value of the local temporary variable is returned to PropertyB.  The result?  PropertyB is not serialized because it is empty.  Additionally, state is not disrupted because everything is restored following serialization.

Certainly, if someone implementing the Class were to serialize the class using System.Xml.Serialization, they would get both properties.  I like this result because there may be a case where an application wants to save or transfer its state to some other application using the same class.  Or maybe a different, third party application might need to consume the state data.  It makes sense that should I deserialize and rehydrate this class, it would be pretty much the same instance.  Of course, context comes into discussion, but not this one.

 

 

 

1/16/2004 10:02:32 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |  Trackback
Tracked by:
"limit texas holdem" (limit texas holdem) [Trackback]
"adipex" (adipex) [Trackback]
"poker table" (poker table) [Trackback]
"quality online casinos" (quality online casinos) [Trackback]
"black jack java online" (black jack java online) [Trackback]
"las vegas surrender roulette rules" (las vegas surrender roulette rules) [Trackback]
"Xanax no prescription online pharmacies" (Xanax no prescription online pharmaci... [Trackback]
"clifford the big red dog fabric" (clifford the big red dog fabric) [Trackback]
"best online black jack" (best online black jack) [Trackback]
"canada online phentermine" (canada online phentermine) [Trackback]
"spielen sie kasino" (spielen sie kasino) [Trackback]
"black casino gambling game jack poker roulette securitydogs" (black casino gamb... [Trackback]
"cheap diet pills without a prescription" (cheap diet pills without a prescripti... [Trackback]
"online casino portals" (online casino portals) [Trackback]
"tamiflu canada" (tamiflu canada) [Trackback]
"tamiflu price" (tamiflu price) [Trackback]
"geschaftsturnier" (geschaftsturnier) [Trackback]
"loans" (loans) [Trackback]
"black jack gaming online" (black jack gaming online) [Trackback]
"prescriptions online with personal check" (prescriptions online with personal c... [Trackback]
"casino download casino game online online-casino-gaming.com" (casino download c... [Trackback]
"xxx free strip poker" (xxx free strip poker) [Trackback]
"pharmacy colleges" (pharmacy colleges) [Trackback]
"1468" (1468) [Trackback]
"hoodia" (hoodia) [Trackback]
"ultram" (ultram) [Trackback]
"diazepam" (diazepam) [Trackback]
"payday loan" (payday loan) [Trackback]
"generic prescriptions online" (generic prescriptions online) [Trackback]
"buy ambien" (buy ambien) [Trackback]
"adipex" (adipex) [Trackback]
"alprazolam" (alprazolam) [Trackback]
"roulette" (roulette) [Trackback]
"parola" (online) [Trackback]
"pro-ana friends" (online) [Trackback]
"manual fiat" (online) [Trackback]
"formal ball gowns" (online) [Trackback]
"debt dsi elimination" (online) [Trackback]
"ankle holsters" (online) [Trackback]
"levine thirty" (title) [Trackback]
"cryptograms" (title) [Trackback]
"a's soon" (besides any) [Trackback]
"asking vw gti parts howbeit" (despite vw gti parts little) [Trackback]
"ww" (ww) [Trackback]
"8f7.lusatop" (8f7.lusatop) [Trackback]
"61e.kolpa.cn" (61e.kolpa.cn) [Trackback]
"5c5.huasv.cn" (5c5.huasv.cn) [Trackback]
"5b2.otudop.cn" (5b2.otudop.cn) [Trackback]
"b69.zipeas.cn" (b69.zipeas.cn) [Trackback]
"f41.hilosa.cn" (f41.hilosa.cn) [Trackback]
"d6a.uvuvla.cn" (d6a.uvuvla.cn) [Trackback]
"c5d.padreti.cn" (c5d.padreti.cn) [Trackback]
"94f.lookaser.cn" (94f.lookaser.cn) [Trackback]
"878.gopaser.cn" (878.gopaser.cn) [Trackback]
"molonline" (molonline) [Trackback]
"zacf.html" (zacf.html) [Trackback]
"zacd.html" (zacd.html) [Trackback]
"laab.html" (laab.html) [Trackback]
"laaq.html" (laaq.html) [Trackback]
"eabc.html" (eabc.html) [Trackback]
"eaap.html" (eaap.html) [Trackback]
"eaai.html" (eaai.html) [Trackback]
"eaad.html" (eaad.html) [Trackback]

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Theme design by Jelle Druyts

Pick a theme: