I'm working with a list of fonts that I serialize and deserialize using DataContractSerializer
. In between the two steps, it's conceivable that the user has removed a font from their machine. I'd like to check a font name as it's being deserialized to ensure that it still exists on the system. If it doesn't exist, that element is not included in the collection returned by DataContractSerializer.ReadObject()
.
Specifically, I'm storing a FontFamily
and serializing a property that gets FontFamily.Name
. In this property's set accessor, I convert the string back into a FontFamily
.
The only reasonable alternative to validation that I can think of would be having the property's set accessor ignore invalid values, and filter out the invalid deserialized objects later. I don't like this option, however - is there a more proper way?