当前位置: 首页>>代码示例>>C#>>正文


C# ProtoReader.AppendExtensionData方法代码示例

本文整理汇总了C#中ProtoReader.AppendExtensionData方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader.AppendExtensionData方法的具体用法?C# ProtoReader.AppendExtensionData怎么用?C# ProtoReader.AppendExtensionData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProtoReader的用法示例。


在下文中一共展示了ProtoReader.AppendExtensionData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

        public object Read(object value, ProtoReader source)
        {
            if (isRootType && value != null) { Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context); }
            int fieldNumber, lastFieldNumber = 0, lastFieldIndex = 0;
            bool fieldHandled;

            //Helpers.DebugWriteLine(">> Reading fields for " + forType.FullName);
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                fieldHandled = false;
                if (fieldNumber < lastFieldNumber)
                {
                    lastFieldNumber = lastFieldIndex = 0;
                }
                for (int i = lastFieldIndex; i < fieldNumbers.Length; i++)
                {
                    if (fieldNumbers[i] == fieldNumber)
                    {
                        IProtoSerializer ser = serializers[i];
                        //Helpers.DebugWriteLine(": " + ser.ToString());
                        if (value == null && ser.ExpectedType == forType) value = CreateInstance(source);
                        if (ser.ReturnsValue) {
                            value = ser.Read(value, source);
                        } else { // pop
                            ser.Read(value, source);
                        }

                        lastFieldIndex = i;
                        lastFieldNumber = fieldNumber;
                        fieldHandled = true;
                        break;
                    }
                }
                if (!fieldHandled)
                {
                    //Helpers.DebugWriteLine(": [" + fieldNumber + "] (unknown)");
                    if (value == null) value = CreateInstance(source);
                    if (isExtensible) {
                        source.AppendExtensionData((IExtensible)value);
                    } else {
                        source.SkipField();
                    }
                }
            }
            //Helpers.DebugWriteLine("<< Reading fields for " + forType.FullName);
            if(value == null) value = CreateInstance(source);
            if (isRootType) { Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context); }
            return value;
        }
开发者ID:helios57,项目名称:anrl,代码行数:49,代码来源:TypeSerializer.cs

示例2: Read

 public object Read(object value, ProtoReader source)
 {
     if (this.isRootType && value != null)
     {
         this.Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
     }
     int num = 0;
     int num2 = 0;
     int num3;
     while ((num3 = source.ReadFieldHeader()) > 0)
     {
         bool flag = false;
         if (num3 < num)
         {
             num2 = (num = 0);
         }
         for (int i = num2; i < this.fieldNumbers.Length; i++)
         {
             if (this.fieldNumbers[i] == num3)
             {
                 IProtoSerializer protoSerializer = this.serializers[i];
                 Type expectedType = protoSerializer.ExpectedType;
                 if (value == null)
                 {
                     if (expectedType == this.forType)
                     {
                         value = this.CreateInstance(source, true);
                     }
                 }
                 else if (expectedType != this.forType && ((IProtoTypeSerializer)protoSerializer).CanCreateInstance() && expectedType.IsSubclassOf(value.GetType()))
                 {
                     value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)protoSerializer).CreateInstance(source));
                 }
                 if (protoSerializer.ReturnsValue)
                 {
                     value = protoSerializer.Read(value, source);
                 }
                 else
                 {
                     protoSerializer.Read(value, source);
                 }
                 num2 = i;
                 num = num3;
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             if (value == null)
             {
                 value = this.CreateInstance(source, true);
             }
             if (this.isExtensible)
             {
                 source.AppendExtensionData((IExtensible)value);
             }
             else
             {
                 source.SkipField();
             }
         }
     }
     if (value == null)
     {
         value = this.CreateInstance(source, true);
     }
     if (this.isRootType)
     {
         this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
     }
     return value;
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:73,代码来源:TypeSerializer.cs


注:本文中的ProtoReader.AppendExtensionData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。