Open AdamsLair opened 9 years ago
Until further notice, TypeInfo
should be regarded as completely unsupported in serialization. Use Type
for serializable fields instead.
Created a StackOverflow Question for gathering some feedback on the matter and seeing if there is something I'm missing.
One possible solution would be to implement some hacky type-conversion code for the sake of compatibility with TypeInfo, in case anyone (or worse, any .Net classes) attempts to serialize one. It should be done in a small protected static method in the Serializer base class, so its usage can easily be tracked. Maybe name it ConvertToTypeInfo
or something.
It would
(obj as Type).GetTypeInfo()
if it is.obj as TypeInfo
if it isn't.It would be used for
Serializer.ReadObject<T>
, depending on T
.Serializer.AssignFieldValue
, depending on the fields type.XmlSerializer.ReadArray
/ BinarySerializer.ReadArray
for each element, depending on the array type. Do the check outside of the loop though and see if that can be moved to Serializer
as well.A typical usage check would test
Type
object.Type
, but deriving from MemberInfo
This should cover all the basic cases.
Making the Duality Core a PCL also requires switching from the old Type API to the new TypeInfo API. Unfortunately, Serialization will have a hard time coping with this, to the point that I would consider TypeInfo completely unsupported as a serializable type.
TypeInfo
derive fromType
in .Net 4.5, but Windows Store apps haveType
derive fromobject
, andTypeInfo
directly fromMemberInfo
.RuntimeType
objects, which derive fromTypeInfo
, which derives fromType
. Thus, the two classes are completely indistinguishable when serializing them, becauseRuntimeType
is simply both of them.TypeInfo
orType
. This choice is purely virtual in .Net 4.5, but distinctive in Windows Store apps. Choosing the wrong one will result in an error when attempting to assign the value to a field or array index.This results in an erroneous deserialization of content, depending on whether the underlying platform implements Type as part of the TypeInfo inheritance or not. There is nothing Duality can do about this, because there is no difference between the two for an object in the .Net 4.5 runtime.