1
protobuf.net을 통해 추상 예제의 속성을 serialize하고 싶습니다.
이 간단한 예제가 작동하도록 내가 무엇을 변경해야하는지 설명해 주시겠습니까? 베이스 클래스에Protobuff.NET - 추상 기본 클래스의 다른 직렬화
using System;
using System.IO;
using ProtoBuf;
namespace TestProtobuf
{
class Program
{
static void Main(string[] args)
{
var x = new ClassB {A = "AAAA", B = "BBBB"};
var memoryStream = new MemoryStream();
Serializer.Serialize(memoryStream,x);
var memoryStream2 = new MemoryStream(memoryStream.ToArray());
var y = Serializer.Deserialize<ClassB>(memoryStream2);
if (x.A != y.A)
Console.Write("Failed");
}
}
[ProtoContract]
public class ClassB:ClassA
{
[ProtoMember(1)]
public string B { get; set; }
}
[ProtoContract]
public abstract class ClassA
{
[ProtoMember(2)]
public string A { get; set; }
}
}