相关疑难解决方法(0)

Protobuf-net 动态类型数组

我不会使用 Protobuf-net 进行一些序列化,并会出现此代码片段的以下错误:

错误:

动态类型不是合同类型:TestType[]

片段:

using System.IO;
namespace QuickStart
{
    class Program
    {
        static void Main()
        {
            //FileAccess.ShowFileAccess();
            //Sockets.ShowSockets();

            var dto = new DataTransferType
            {
                ProtoDynamicProperty = new TestType[]
                {
                    new TestType {UselessProperty="AAA"},
                    new TestType{UselessProperty="BBB"},
                    new TestType{UselessProperty="CCC"}
                }
            };

            using (MemoryStream testStream = new MemoryStream())
            {
                ProtoBuf.Serializer.SerializeWithLengthPrefix(testStream, dto, ProtoBuf.PrefixStyle.Base128);
            }
        }


    }
    [ProtoBuf.ProtoContract]
    struct TestType
    {
        [ProtoBuf.ProtoMember(1)]
        public string UselessProperty { get; set; }
    }

    [ProtoBuf.ProtoContract]
    class DataTransferType
    {
        [ProtoBuf.ProtoMember(1, DynamicType = true)]
        public object ProtoDynamicProperty { get; set; …
Run Code Online (Sandbox Code Playgroud)

serialization object protobuf-net dynamictype

5
推荐指数
1
解决办法
1614
查看次数

标签 统计

dynamictype ×1

object ×1

protobuf-net ×1

serialization ×1