public virtual byte[] Serialize(object value)
 {
     ClrBinarySerializer.CacheItem cacheItem = this.SerializeImpl(value);
     byte[] numArray = new byte[cacheItem.Data.Count + 2];
     Array.Copy((Array)BitConverter.GetBytes(cacheItem.Flags), 0, (Array)numArray, 0, 2);
     Array.Copy((Array)cacheItem.Data.Array, cacheItem.Data.Offset, (Array)numArray, 2, cacheItem.Data.Count);
     return(numArray);
 }
        private object Deserialize(ClrBinarySerializer.CacheItem item)
        {
            if (item.Data.Array == null)
            {
                return((object)null);
            }
            if ((int)item.Flags == 64082)
            {
                ArraySegment <byte> data = item.Data;
                if (data.Count == data.Array.Length)
                {
                    return((object)data.Array);
                }
                byte[] numArray = new byte[data.Count];
                Array.Copy((Array)data.Array, data.Offset, (Array)numArray, 0, data.Count);
                return((object)numArray);
            }
            TypeCode            typeCode = (TypeCode)((int)item.Flags & (int)byte.MaxValue);
            ArraySegment <byte> data1    = item.Data;

            switch (typeCode)
            {
            case TypeCode.Empty:
                if (data1.Array != null && data1.Count != 0)
                {
                    return((object)this.DeserializeString(data1));
                }
                return((object)null);

            case TypeCode.Object:
                return(this.DeserializeObject(data1));

            case TypeCode.DBNull:
                return((object)null);

            case TypeCode.Boolean:
                return((object)this.DeserializeBoolean(data1));

            case TypeCode.Char:
                return((object)this.DeserializeChar(data1));

            case TypeCode.Int16:
                return((object)this.DeserializeInt16(data1));

            case TypeCode.UInt16:
                return((object)this.DeserializeUInt16(data1));

            case TypeCode.Int32:
                return((object)this.DeserializeInt32(data1));

            case TypeCode.UInt32:
                return((object)this.DeserializeUInt32(data1));

            case TypeCode.Int64:
                return((object)this.DeserializeInt64(data1));

            case TypeCode.UInt64:
                return((object)this.DeserializeUInt64(data1));

            case TypeCode.Single:
                return((object)this.DeserializeSingle(data1));

            case TypeCode.Double:
                return((object)this.DeserializeDouble(data1));

            case TypeCode.Decimal:
                return((object)this.DeserializeDecimal(data1));

            case TypeCode.DateTime:
                return((object)this.DeserializeDateTime(data1));

            case TypeCode.String:
                return((object)this.DeserializeString(data1));

            default:
                throw new InvalidOperationException("Unknown TypeCode was returned: " + (object)typeCode);
            }
        }