【发布时间】:2017-06-14 19:52:06
【问题描述】:
我一直在使用 MessagePackKnownCollectionItemTypeAttribute,例如
[MessagePackKnownCollectionItemTypeAttribute( "MyAbstractBase", typeof( MyImpl ) )]
Dictionary<int, MyAbstractBase> class_member;
这很好用,但如果我有呢:
[MessagePackKnownCollectionItemTypeAttribute( "MyAbstractBase", typeof( MyImpl ) )]
Dictionary<int, Dictionary<int, MyAbstractBase>> class_member;
上述方法不起作用,我得到“不支持此操作,因为无法实例化 'MyAbstractBase'。” (在运行时,当我实例化一个序列化程序时)。
我也试过
[MessagePackKnownCollectionItemTypeAttribute( "MyAbstractBase", typeof( Dictionary<int, MyImpl> ) )]
Dictionary<int, Dictionary<int, MyAbstractBase>> class_member;
这给出了同样的错误。
有没有办法像这样处理嵌套字典中的抽象类? 谢谢!
【问题讨论】:
标签: c# nested polymorphism abstract msgpack