當前位置: 首頁>>代碼示例>>C#>>正文


C# Local.AfterDeserialize方法代碼示例

本文整理匯總了C#中System.Local.AfterDeserialize方法的典型用法代碼示例。如果您正苦於以下問題:C# Local.AfterDeserialize方法的具體用法?C# Local.AfterDeserialize怎麽用?C# Local.AfterDeserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Local的用法示例。


在下文中一共展示了Local.AfterDeserialize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Deserialize

        /// <summary>Takes the remaining content of the stream and deserialze it into the instance.</summary>
        internal static Local.LocalFeatures Deserialize(Stream stream, Local.LocalFeatures instance)
        {
            var br = new BinaryReader(stream);
            instance.MyEnum = LocalFeatureTest.TopEnum.First;
            while (true)
            {
                int keyByte = stream.ReadByte();
                if (keyByte == -1)
                    break;
                // Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                    // Field 1 Varint
                    case 8:
                        instance.Uptime = new TimeSpan((long)(long)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream));
                        continue;
                    // Field 2 Varint
                    case 16:
                        instance.DueDate = new DateTime((long)(long)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream), DateTimeKind.Utc);
                        continue;
                    // Field 3 Fixed64
                    case 25:
                        instance.Amount = br.ReadDouble();
                        continue;
                    // Field 4 LengthDelimited
                    case 34:
                        instance.Denial = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 5 LengthDelimited
                    case 42:
                        instance.Secret = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 6 LengthDelimited
                    case 50:
                        instance.Internal = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 7 LengthDelimited
                    case 58:
                        instance.PR = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 8 LengthDelimited
                    case 66:
                        Mine.MyMessageV1.DeserializeLengthDelimited(stream, instance.TestingReadOnly);
                        continue;
                    // Field 9 LengthDelimited
                    case 74:
                        if (instance.MyInterface == null)
                            throw new InvalidOperationException("Can't deserialize into a interfaces null pointer");
                        else
                            LocalFeatureTest.InterfaceTestSerializer.DeserializeLengthDelimited(stream, instance.MyInterface);
                        continue;
                    // Field 10 LengthDelimited
                    case 82:
                        LocalFeatureTest.StructTest.DeserializeLengthDelimited(stream, ref instance.MyStruct);
                        continue;
                    // Field 11 LengthDelimited
                    case 90:
                        TestB.ExternalStructSerializer.DeserializeLengthDelimited(stream, ref instance.MyExtStruct);
                        continue;
                    // Field 12 LengthDelimited
                    case 98:
                        if (instance.MyExtClass == null)
                            instance.MyExtClass = TestB.ExternalClassSerializer.DeserializeLengthDelimited(stream);
                        else
                            TestB.ExternalClassSerializer.DeserializeLengthDelimited(stream, instance.MyExtClass);
                        continue;
                    // Field 13 Varint
                    case 104:
                        instance.MyEnum = (LocalFeatureTest.TopEnum)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream);
                        continue;
                }

                var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream);

                // Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                    case 0:
                        throw new global::SilentOrbit.ProtocolBuffers.ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    default:
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.SkipKey(stream, key);
                        break;
                }
            }

            instance.AfterDeserialize();
            return instance;
        }
開發者ID:StepWoodProductions,項目名稱:ProtoBuf,代碼行數:89,代碼來源:GeneratedLocal.Serializer.cs


注:本文中的System.Local.AfterDeserialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。