Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use jaguar_serializer plugin to convert below csharp code to dart? #175

Open
NTMS2017 opened this issue Apr 22, 2019 · 0 comments
Open

Comments

@NTMS2017
Copy link

I have a csharp code and I am not sure if this plugin serialise the object to byte array.

Below example uses Xml.Serialization. how to use jaguar_serializer in same manner of the below csharp code? The object is a class.

So main question is how to use jaguar_serializer plugin to convert below csharp code to dart?

private static readonly Object locker = new Object();

private static byte[] ObjectToByteArray(Object objectToSerialize)
{            
    MemoryStream ms = new MemoryStream();
    //BinaryFormatter formatter = new BinaryFormatter();            
    System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(objectToSerialize.GetType());
    try
    {
        //Here's the core functionality! One Line!
        //To be thread-safe we lock the object
        lock (locker)
        {
            x.Serialize(ms, objectToSerialize);
            //formatter.Serialize(fs, objectToSerialize);
        }
        //return fs.ToArray();                
        return ms.ToArray();
    }
    catch (SerializationException se)
    {                
        return null;
    }
    finally
    {
        //fs.Close();
        ms.Close();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant