Mike Rebosse
Mike Rebosse

Reputation: 139

Can Protobuf.Net Serialize a Dynamic Dictionary?

I have a dictionary that is Dynamic.

public Dictionary<int, dynamic> Data = new Dictionary<int, dynamic>();

The dynamic portion will contain simple classes just consisting of 5-6 get/set properties for instance the classes look like.

public class Class1
{
    public int Property1 { get; set; }
    public int Property2 { get; set; }
}

and

public class Class2
{
    public string Property1 { get; set; }
    public string Property2 { get; set; }
}

I tried adding these 2 classes to my dictionary and then serializing the dictionary but received an error. Was just wondering If Protobuf.Net is able to Serialize and De-serialize such a Dictionary? and If so, how is this accomplished?

Upvotes: 3

Views: 623

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062955

The short answer would be "not really". There are probably ways that it could be made to work, but I wouldn't recommend it - it would be hard to maintain.

protobuf-net (and protobuf generally) works best when the serializer knows the structure in advance.

Upvotes: 3

Related Questions