c# - Best practices to migrate to version 2 of a type with Json.NET during an upgrade -
currently have type attribute signal properties must encrypted before persisting info disk. utilize reflection see properties decorated confidentialattribute, encrypt values , serialize. on deserialization decrypt confidentialattribute decorated properties. here simplified illustration of type looks like.
class myobject_v1 { [confidential] public string stringdata { get; set; } }
we doing refactoring/clean , plan rid of confidentialattribute , utilize this.
class myobject_v2 { public confidentialstring stringdata { get; set; } } class confidentialstring { [onserializing] public void serialize(streamingcontext context) { //encrypt value... } [ondeserialized] public void deserialized(streamingcontext context) { //decrypt value... } public string value { get; set; } }
we have requirement maintain configuration info during upgrade. question best practice migrating configuration of myobject_v1 persisted disk myobject_v2 persisted disk. options thinking of having classes live side side or perhaps having both properties live side side logic migration 1 time object accessed first time.
thanks help.
if understand requirements correctly, should easy. easy won't have anything!
myobject_v1
should produce exact same output when serialized myobject_v2
. myobject_v1
serialized before alter should deserialize myobject_v2
without modification. need implement serialize
, deserialize
methods correctly.
also, best practice possible: maintain total backward compatibility, , create refactoring impact implementation détails. if can maintain configuration files same way while refactoring code, so.
to sum up: best way migrate info not having migrate @ all!
c# json.net
No comments:
Post a Comment