我想知道在使用Silverlight 4客户端时是否可以按this answer中描述的方式配置已知类型?
只有似乎有效的方法是使用KnownType
属性,我们希望避免使用该解决方案,因为这些类位于不同的程序集中,我们不希望它们之间存在依赖关系。
以下是配置示例:
<?xml version="1.0"?>
<configuration>
<!-- *snip* -->
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="Foo.Dto.FooDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL">
<knownType type="Foo.Dto.BarDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
<knownType type="Foo.Dto.BizDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
<!-- *snip* -->
</configuration>
答案 0 :(得分:1)
查看有关该主题的MSDN docs - 基本上,这就是您所需要的:
<configuration>
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="MyCompany.Library.Shape, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL">
<knownType type="MyCompany.Library.Circle, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
</configuration>