Exemplo n.º 1
0
        public object GetObjectToSerialize(object obj, Type targetType)
        {
            if (obj is NonSerializablePerson)
            {
                NonSerializablePerson          nsp = (NonSerializablePerson)obj;
                NonSerializablePersonSurrogate serializablePerson = new NonSerializablePersonSurrogate
                {
                    Name = nsp.Name,
                    Age  = nsp.Age,
                };

                return(serializablePerson);
            }
            else if (obj is NonSerializablePersonForStress)
            {
                NonSerializablePersonForStress          nsp = (NonSerializablePersonForStress)obj;
                NonSerializablePersonForStressSurrogate serializablePerson = new NonSerializablePersonForStressSurrogate
                {
                    Name = nsp.Name,
                    Age  = nsp.Age,
                };

                return(serializablePerson);
            }

            return(obj);
        }
Exemplo n.º 2
0
        public object GetDeserializedObject(object obj, Type targetType)
        {
            if (obj is NonSerializablePersonSurrogate)
            {
                NonSerializablePersonSurrogate person = (NonSerializablePersonSurrogate)obj;
                return(new NonSerializablePerson(person.Name, person.Age));
            }
            else if (obj is NonSerializablePersonForStressSurrogate)
            {
                NonSerializablePersonForStressSurrogate person = (NonSerializablePersonForStressSurrogate)obj;
                return(new NonSerializablePersonForStress(person.Name, person.Age));
            }

            return(obj);
        }