protobuf网[德]跨越边界的装配序列 [英] protobuf-net [de]serializing across assembly boundaries
问题描述
我有一个程序集的基类,而在另一个是从基类继承的大量生成的类。使用protobuf网(R282)来序列化基本类型的列表,试图解决subclassType(SerializerT.cs行248),因为子类不在基类的部件时失败。移动一起上课是不是一个更好的选择,而且我可以绕过名单是相当重要的。
I have a base class in one assembly and a large number of generated classes in another that inherit from the base class. Using protobuf-net (r282) to serialize a list of the base type fails when attempting to resolve the subclassType (line 248 of SerializerT.cs) because the subclass is not in the assembly of the base class. Moving the classes together is not a preferred option and it is rather important that I can pass around List.
下面是我的标签基类。所包含的类型都标有 ProtoMember(X)
的要求。
Here is my tagged base class. The included types are marked with ProtoMember(x)
as required.
[ProtoContract]
[ProtoInclude(1,"SomeItemType")]
[ProtoInclude(2,"AnotherItemType")]
[ProtoInclude(190,"YetAnotherItemType")]
public abstract class BaseItem
{
}
作为一个方面说明,这是部分使用protobuf网更换为BinaryFormatter的桌面应用程序和Web服务的SOAP之间移动数据评估。
As a side note, this is part of evaluating using protobuf-net to replace BinaryFormatter for moving data between a desktop app and a SOAP webservice.
我可以做这种事情呢?有没有更好的办法?我只是缺少明显的东西?一个单独的长期的问题是我应该做的事情略有不同,为最终搬迁准备3.5?
Can I do this sort of thing at all? Is there a better way? Am I just missing something obvious? A separate longer term question is should I be doing anything slightly different to prepare for an eventual move to 3.5?
推荐答案
也许最简单的自动使用方式 ProtoInclude
与的typeof
,因为这会处理很多细微之处给你:
Perhaps the easiest way to use ProtoInclude
is with typeof
, since this will handle a lot of the nuances for you automatically:
[ProtoInclude(1, typeof(SomeItemType))]
另外,你可以只使用集限定的名称,所以:
Alternatively you can just use assembly-qualified names, so:
[ProtoInclude(1,"SomeItemType, SomeRandomAssembly")]
在一个比较奇特的案件涉及多个的AppDomain
S,我发现你也可以工作,一些魔法与 AppDomain.TypeResolve
事件,但应尽可能避免。我也有在管道中的元数据层的一个完整的重新工作,允许更多的灵活性在运行时(而不是在编译申报全部的寄托,这是造成某些上面的疼痛)。
In a rather peculiar case involving multiple AppDomain
s, I've found you can also work some magic with the AppDomain.TypeResolve
event, but that should be avoided if possible. I also have a complete re-working of the metadata layer in the pipeline, allowing much more flexibility at runtime (rather than having to declare everthing at compile, which is causing some of the pain above).
这篇关于protobuf网[德]跨越边界的装配序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!