Interfaces with protobuf-net and C#

前端 未结 1 405
甜味超标
甜味超标 2021-01-19 12:38

Does anybody know what is the right way to set up a ProtoContract for an Interface?

I get the following exception \"The type cannot be

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 12:59

    Interesting; yes, it looks like something is up there. However, it does work when exposed as a member, i.e.

    [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(ms);
            }
            // here clone.Content *is* a Lesson5TestClass2 instance
        }
    }
    

    I will have to look to see what is up with interface support as the root object.

    0 讨论(0)
提交回复
热议问题