Why is ISet not supported?
inethui opened this issue · 10 comments
The following code throws an exception complaining no default constructor. I verified that IList, IDictionary, ICollection all work fine,
[Fact]
public void ISetTest()
{
MetaType metaType = RuntimeTypeModel.Default.Add(typeof(WithISet), true);
metaType.AddField(1, "_set").SetSettings(x => x.V.Format = ValueFormat.LateReference);
RuntimeTypeModel.Default.CompileInPlace();
}
private class WithISet
{
public readonly ISet<int> _set;
}
Also, does Aqla support IReadOnlyDictionary, IReadOnlyCollection, IReadOnlySet?
You are right, they must be supported. They simply did not exist at the time of active development of AqlaSerializer. I'm going to add support for them some time later.
The complicated thing here is that non generic ICollection
doesn't have an Add
method so I had to use IList
.
Is there any updates on this issue? When can we get the solution for it?
It turned out to be easier than I thought. I already have a working implemention of ISet support.
I uploaded a new version with all these interfaces supported. Please confirm that it works on your side.
It works at interface level. However, what I serialized type is different from the deserialized type:
System.Collections.ObjectModel.ReadOnlyCollection -> System.Collections.Generic.List
System.Collections.ObjectModel.ReadOnlyDictionary<string, int> -> System.Collections.Generic.Dictionary<string, int>
Is it possible to deserialize back the same type as serialized?
No, but you can make surrogates for them. What is your usage scenario so that you care about underlying type? In OOP you should not downcast things, you are expected to use them only by provided interfaces.
We have unit tests which compare the objects before and after serialization. The comparison verifies the object types to make sure that through deep cloning, we get exactly the same object back.
Ok. As I said you can use surrogates to hook into serialization process.
I don't see how type changing like this may cause an issue in a real app so I'm closing this.