Serialization of Nemerle.Core.list

6 views
Skip to first unread message

emp...@gmail.com

unread,
Jun 15, 2009, 5:36:06 PM6/15/09
to Nemerle Forum
I realized Nemerle.Core.list is not serializable. (It doesn't have the
serializable attribute). This has some implications like when you need
serializable collections you drop down to SCG.List<T> which is not
nemerle way. What do you think ? Should we make Nemerle.Core.list
serializable ?

Ķaмĭļ ๏ Şκaļşκĭ

unread,
Jun 15, 2009, 5:59:40 PM6/15/09
to nemer...@googlegroups.com
This is not possible for some weird reason. AFAIR it was something
like: if you want to make IEnumerable class serializable, it also
needs to implement ICollection. In case of list['a], which is
immutable, we do not implement ICollection (which has fields like Add
/ Remove), so it is not possible... I'm not sure this is exactly the
reason, but something like this - if you try to make list as
serializable and create a testcase, then I think you will get runtime
error explaining it more.
--
Kamil Skalski
http://kamil-skalski.pl

ReverseBlade

unread,
Jun 15, 2009, 6:29:31 PM6/15/09
to Nemerle Forum
Yeah I checked that. For XmlSerialization it asks for "Add" method
which obviously can't exist for our beloved immutable collection list.

Binary Serialization works though.

On Jun 16, 12:59 am, Ķaмĭļ ๏ Şκaļşκĭ <kamil.skal...@gmail.com> wrote:
> This is not possible for some weird reason. AFAIR it was something
> like: if you want to make IEnumerable class serializable, it also
> needs to implement ICollection. In case of list['a], which is
> immutable, we do not implement ICollection (which has fields like Add
> / Remove), so it is not possible... I'm not sure this is exactly the
> reason, but something like this - if you try to make list as
> serializable and create a testcase, then I think you will get runtime
> error explaining it more.
>

Ķaмĭļ ๏ Şκaļşκĭ

unread,
Jun 16, 2009, 3:23:07 AM6/16/09
to nemer...@googlegroups.com
On Tue, Jun 16, 2009 at 12:29 AM, ReverseBlade<emp...@gmail.com> wrote:
>
> Yeah I checked that. For XmlSerialization it asks for "Add" method
> which obviously can't exist for our beloved immutable collection list.
>
> Binary Serialization works though.

Ah, and with binary serialization I remember there was some bug
related to generics or something... Did you verify that it works? If
then, it's reasonable to maybe add Serializable and let it fail at
runtime for XML serialization, but work for binary.

>
> On Jun 16, 12:59 am, Ķaмĭļ ๏ Şκaļşκĭ <kamil.skal...@gmail.com> wrote:
>> This is not possible for some weird reason. AFAIR it was something
>> like: if you want to make IEnumerable class serializable, it also
>> needs to implement ICollection. In case of list['a], which is
>> immutable, we do not implement ICollection (which has fields like Add
>> / Remove), so it is not possible... I'm not sure this is exactly the
>> reason, but something like this - if you try to make list as
>> serializable and create a testcase, then I think you will get runtime
>> error explaining it more.
>>
>> On Mon, Jun 15, 2009 at 11:36 PM, empe...@gmail.com<empe...@gmail.com> wrote:
>>
>> > I realized Nemerle.Core.list is not serializable. (It doesn't have the
>> > serializable attribute). This has some implications like when you need
>> > serializable collections you drop down to SCG.List<T> which is not
>> > nemerle way. What do you think ? Should we make Nemerle.Core.list
>> > serializable ?
>>
>> --
>> Kamil Skalskihttp://kamil-skalski.pl
> >
>



VladD2

unread,
Jun 16, 2009, 8:47:54 AM6/16/09
to nemer...@googlegroups.com
2009/6/16 Ķaмĭļ ๏ Şκaļşκĭ <kamil....@gmail.com>


This is not possible for some weird reason. AFAIR it was something
like: if you want to make IEnumerable class serializable, it also
needs to implement ICollection. In case of list['a], which is
immutable, we do not implement ICollection (which has fields like Add
/ Remove), so it is not possible... I'm not sure this is exactly the
reason, but something like this - if you try to make list as
serializable and create a testcase, then I think you will get runtime
error explaining it more.

We can use ISerializable or SerializationSurrogate.
See http://msdn.microsoft.com/en-us/magazine/cc188950.aspx

VladD2

unread,
Jun 16, 2009, 9:14:18 AM6/16/09
to nemer...@googlegroups.com
I think, simple way is implement ISerializable and IDeserializationCallback.
But I not sure can we modify created instance of list[T].Cons.

What means Nemerle.Extensions.CompilerMutable in tl field?

In worst case we can try use reflection to set fields in OnDeserialization().

2009/6/16 VladD2 <v...@rsdn.ru>:

--
С уважением,
Чистяков Владислав,
www.rsdn.ru

ReverseBlade

unread,
Jun 20, 2009, 1:28:20 PM6/20/09
to Nemerle Forum
Well I tried a relatively complex example as below and it seems to be
working. I think we can mark it as serializable.


using System;
using System.Console;
using Nemerle.Utility;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Xml.Serialization;
module Program
{
Main() : void
{
def testObject = Doo();
def someList = System.Collections.Generic.List.[Doo]();
someList.Add(testObject);
testObject.InnerList = [someList];

using( def m = MemoryStream())
{
def bf = BinaryFormatter();
bf.Serialize(m,testObject);
m.Seek(0,0);
def newTestObject : Doo = bf.Deserialize(m) :> Doo;
Console.Write(newTestObject.InnerList.Head[0].Foo);
}


}
}

[Serializable]

public class Doo {
public Foo:Foo = Foo.Bar();
public InnerList:list[System.Collections.Generic.List.[Doo]]
{ get; set;}
}


[Serializable]
public variant Foo
{
[Serializable]
|Bar
[Serializable]
|Baz
}


/// Outputs Foo+Bar which is correct.

On Jun 16, 4:14 pm, VladD2 <v...@rsdn.ru> wrote:
> I think, simple way is implement ISerializable  and IDeserializationCallback.
> But I not sure can we modify created instance of list[T].Cons.
>
> What means Nemerle.Extensions.CompilerMutable in tl field?
>
> In worst case we can try use reflection to set fields in OnDeserialization().
>
> 2009/6/16 VladD2 <v...@rsdn.ru>:
>
> > 2009/6/16 Ķaмĭļ ๏ Şκaļşκĭ <kamil.skal...@gmail.com>
>
> >> This is not possible for some weird reason. AFAIR it was something
> >> like: if you want to make IEnumerable class serializable, it also
> >> needs to implement ICollection. In case of list['a], which is
> >> immutable, we do not implement ICollection (which has fields like Add
> >> / Remove), so it is not possible... I'm not sure this is exactly the
> >> reason, but something like this - if you try to make list as
> >> serializable and create a testcase, then I think you will get runtime
> >> error explaining it more.
>
> > We can use ISerializable or SerializationSurrogate.
> > Seehttp://msdn.microsoft.com/en-us/magazine/cc188950.aspx
Reply all
Reply to author
Forward
0 new messages