[mono-android] Being driven insane....

Dean Cleaver dean.cleaver at xceptionsoftware.com
Sun Nov 27 13:22:50 EST 2011


Paul,

Not followed the rest of the thread, but this is what I often do for Serializable objects to be able to use them as strings:

public class Foo
{
    public override string ToString()
    {
        return Serialize(this);
    }

    public static Foo Deserialize(string serializedData)
    {
        if (string.IsNullOrEmpty(serializedData))
            return new Foo();

        XmlSerializer serializer = new XmlSerializer(typeof(Foo));
        StringReader reader = new StringReader(serializedData);
        return (Foo)serializer.Deserialize(reader);
    }

    public static string Serialize(Foo foo)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Foo));
        StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
        serializer.Serialize(writer, foo);
        return writer.ToString();
    }
}

Thus you can either use foo.ToString() or Foo.Serialize(foo) to get the serialized object in a string, and Foo.Deserialize(string) to get the class back. I've used this a lot in TCP-IP communications.

Dino

-----Original Message-----
From: monodroid-bounces at lists.ximian.com [mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Paul Johnson
Sent: Wednesday, November 23, 2011 9:21 AM
To: Discussions related to Mono for Android
Subject: [mono-android] Being driven insane....

Hi,

This is driving me mad....

I have a class called foo with [Serialize] above it to serialize it.

In the main tab constructor, I have

Bundle b;
b.PutSerializable("data", foo);
intent.PutExtras(b);

Should be ok, except for PutSerializable it needs to be Java.IO.ISerializable

Putting (Java.IO.ISerializable)foo doesn't cut it either.

I don't know what the difference is between a C# and Java serializable object is.

So you can see it in context, I've uploaded my project...
http://www.all-the-johnsons.co.uk/android/AndroidTimeOfDeath.zip

I'm trying to find a simple way to pass a class between tabs and it's annoying me now!

Any help would be appreciated.

Thanks

Paul
_______________________________________________
Monodroid mailing list
Monodroid at lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid


More information about the Monodroid mailing list