I am using xml serialization but now came across a runtime error I haven't seen before.
"To be XML serializable, types which
inherit from IEnumerable must have an
implementation of Add(System.Object)
at all levels of their inheritance
hierarchy. ImageEditor.EffectOptions
does not implement Add(System.Object)"
It seems a little weird to be forced to implement a method via runtime exception, rather than compile time error such as missing methods from implemented interfaces.
Is this by design? Should this not be enforced via some sort of interface like XmlSerializable
, etc?
Other than this I am wondering if the serializer guarantees passing a value of the right type where I can just cast it to the type, which in my case is EffectOption
.
Or should I implement this Add (object)
method to see if the object is of type EffectOption
and if not throw an exception?
I haven't implemented this Add (object)
method before but my guess is it's safer to just cast it to EffectOption
and add it to EffectOptions
collection.
EDIT: Here's the type itself:
public class EffectOptions : IEnumerable<EffectOption>
{
public List<EffectOption> Options { get; private set; }
//IEnumerable methods
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…