有谁知道建立一个的正确方法是什么合约原型 for an 界面?
我收到以下异常“一旦生成序列化器,类型就无法更改“仅使用属性。
使用的代码:
[ProtoContract]
public class Lesson5TestClass2 : ILesson5TestInteface1
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public string Phone { get; set; }
}
[ProtoContract]
[ProtoInclude(1000, typeof(Lesson5TestClass2))]
public interface ILesson5TestInteface1
{
[ProtoMember(1)]
string Name { get; set; }
[ProtoMember(2)]
string Phone { get; set; }
}
仅当添加以下设置时,我才能反序列化:
RuntimeTypeModel.Default.Add(typeof (ILesson5TestInteface1), true)
.AddSubType(50, typeof(Lesson5TestClass2));
我真的很想仅使用属性来配置它。
我正在使用 NuGet 的 protobuf-net r470。
顺便说一句:这个例子来自一组“测试经验教训”,展示了如何为我的同事使用 protobuf-net 进行序列化。
谢谢阅读 :)
有趣的;是的,上面好像有东西。然而,它does当暴露为成员时工作,即
[ProtoContract]
class Wrapper
{
[ProtoMember(1)]
public ILesson5TestInteface1 Content { get; set; }
}
static class Program
{
static void Main()
{
Wrapper obj = new Wrapper
{
Content = new Lesson5TestClass2()
}, clone;
using(var ms = new MemoryStream())
{
Serializer.Serialize(ms, obj);
ms.Position = 0;
clone = Serializer.Deserialize<Wrapper>(ms);
}
// here clone.Content *is* a Lesson5TestClass2 instance
}
}
我将不得不看看接口支持的情况如何root object.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)