Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Writing a C# serializer, running into an issue

$
0
0

@jamie_yello wrote:

I wrote a class that takes an object and outputs a .cs file with code that generates that object. Aka an object to class converter.

https://pastebin.com/WDLygCRs

I'm making this because I'm writing my own custom Windows-forms within monogame, and I want to replicate the experience you get coding with Windows forms/Qt.

My issue is that Monogame's Color does not expose its 'innards', and that I cannot serialize it.

    Color test = new Color();
    List<string> dependencies = new List<string>();
    Debug.WriteLine("Serialation of test color;\n" + CSCreator.CreateFields(test, ref dependencies));

This should output something like
byte R = 55, byte G = 87; byte B = 9; byte A = 98;

But instead it outputs nothing. This is because color.GetType().GetFields() outputs nothing.

Of course I could write an exception for Color, but I'd much rather find a generic way to handle all Monogame objects like this. I'm not sure when this is going to happen with what objects.

Edit: on looking at the source code for color, I saw it uses the
[System.Runtime.Serialization.DataContractAttribute]

It seems like I have to write a method that will invoke Deconstruct, which will be difficult, as every object has a different set of parameters, but it should be manageable.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles