I have a Windows Phone 7 project that connects to a .NET web service to fetch data on demand. Both the WP7 project and the web service use a copy of the same c# class library. Part of this library is an enum of EmployeeType
:
Public enum EmployeeType
{
Standard = 0,
TeamLeader = 105
}
Since the app was released, the web service class library has had a change made to it - adding a new enum value. (SeniorManager = 110
)
Therefore, when I receive an object on the phone with a property containing the new enum value, I get a SerializationException
when attempting to add it to IsolatedStorage. This is because the new enum value cannot be serialized, as the WP7 class library has not had the same update made to it and the enum value does not exist.
What I would like to achieve is to still be able to serialize the object, but ignore the invalid enum value, or replace it with a valid one (ideally Standard = 0
).
This will enable me to handle any future additions made to the web service enum, without breaking the functionality of the app.
Notes:
- The enum/values above are contrived for the purposes of the question and not the actual enum in question.
- The fact that the value would be serialized with an incorrect value is unimportant for the purposes of the app.
Thanks!