public object GetObjectToSerialize(object obj, Type targetType)
 {
     //This method is called on serialization.
     //If we're serializing Person,...
     if (obj is Person)
     {
         Person person = (Person)obj;
         PersonSurrogated personSurrogated = new PersonSurrogated();
         personSurrogated.FirstName = person.firstName;
         personSurrogated.LastName = person.lastName;
         personSurrogated.Age = person.age;
         return personSurrogated;
     }
     return obj;
 }
Пример #2
0
 public object GetDeserializedObject(object obj, Type targetType)
 {
     //This method is called on deserialization.
     //If we're deserializing PersonSurrogated,...
     if (obj is PersonSurrogated)
     {
         PersonSurrogated personSurrogated = (PersonSurrogated)obj;
         Person           person           = new Person();
         person.firstName = personSurrogated.FirstName;
         person.lastName  = personSurrogated.LastName;
         person.age       = personSurrogated.Age;
         return(person);
     }
     return(obj);
 }