public interface IYObject
{
string X { get; }
}
public class YObject : IYObject
{
public string X { get; set; }
}
public class D
{
public IYObject Y { get; set; }
}
class Program
{
static void Main()
{
var m = RuntimeTypeModel.Default;
m.Add(typeof(D), true).Add("Y");
m.Add(typeof(IYObject), false).AddSubType(1, typeof(YObject)).Add("X");
var d = new D { Y = new YObject { X = "a" } };
using (var ms = new MemoryStream())
{
Serializer.Serialize(ms, d);
ms.Position = 0;
var d2 = Serializer.Deserialize<D>(ms);
Debug.Assert(d.Y.X == d2.Y.X);
}
}
}
Код дает сбой, когда я пытаюсь добавить подтип к IYObject
:
System.InvalidOperationException occurred
Message=Sub-types can only be adedd to non-sealed classes
Source=protobuf-net
StackTrace:
at ProtoBuf.Meta.MetaType.AddSubType(Int32 fieldNumber, Type derivedType)
InnerException: