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

Abstract class deserialization #150

Open
cHullaert opened this issue Dec 1, 2017 · 1 comment
Open

Abstract class deserialization #150

cHullaert opened this issue Dec 1, 2017 · 1 comment

Comments

@cHullaert
Copy link

Hi,

thanks for the project, here is my code to redefine the converter for an abstract class.

`public class PayloadConverter: fsDirectConverter {
protected override fsResult DoSerialize(Payload model, Dictionary<string, fsData> serialized) {
serialized.Add("type", new fsData("add"));

    return fsResult.Success;
}

protected override fsResult DoDeserialize(Dictionary<string, fsData> data, ref Payload model) {                
    return fsResult.Success;
}

public override object CreateInstance(fsData data, Type storageType) {
    Payload payload=null;

    string payloadType=data.AsDictionary["type"].AsString;
    switch(payloadType) {
        case "add": 
            payload=new AddObjectPayload();
            break;
        case "move": 
            payload=new MoveObjectPayload();
            break;
    } 
      
    return payload;
}

}`

Just missing the "standard" code for serialization / deserialiation of my object based on its reference without inistantiate it. Have I to duplicate all code or maybe there is a magic function to do this?

Thanks a lot.
Christof

@cHullaert
Copy link
Author

I've also found something with $type but then I don't know how to register the type.

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