I have a class hierarchy that looks like this. These classes contain a lot of other details which I have excluded. This is a simplification to focus on the serialization aspect of these classes.
[ProtoInclude(1, typeof(Query<bool>))]
[ProtoInclude(2, typeof(Query<string>))]
[ProtoInclude(3, typeof(Query<int>))]
[ProtoInclude(4, typeof(Query<decimal>))]
[ProtoInclude(5, typeof(Query<DataSet>))]
abstract class Query
{
public string Result { get; set; }
}
[ProtoInclude(1, typeof(SpecialQuery)]
abstract class Query<T> : Query
{
public new T Result { get; set; }
}
abstract class SpecialQuery : Query<DataSet>
{
public new string Result { get; set; }
}
I also have about 150 auto-generated descendants of generic Query, with a large variety of generic types. For example:
[ProtoContract]
class W : Query<bool>
{
}
[ProtoContract]
class X : Query<string>
{
}
[ProtoContract]
class Y : Query<int>
{
}
[ProtoContract]
class Z : SpecialQuery
{
}
I've also autogenerated [ProtoInclude] for all those types. For example:
[ProtoInclude(1, typeof(W)]
[ProtoInclude(2, typeof(X)]
[ProtoInclude(3, typeof(Y)]
[ProtoInclude(4, typeof(Z)]
The question is, how do I deploy those 150 ProtoIncludes? I've tried various combinations that seem logical, but I get various exceptions depending on which attributes are present where. The types that are actually need serialization in the above example would be W, X, Y, Z, only there's about 150 of them.
Can protobuf-net even deal with something like this, or should I try some other kind of serialization?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…