Пример #1
0
        private void WriteGenericList(BinaryWriter writer, IEnumerable array)
        {
            int count = 0;
            var col   = array as ICollection;

            if (col != null)
            {
                count = (int)col.Count;
            }
            else
            {
                foreach (object obj in array)
                {
                    count++;
                }
            }
            var itemType = GetBoisMemberInfo(array.GetType().GetGenericArguments()[0]);

            // Int32
            PrimitivesConvertion.WriteVarInt(writer, count);
            foreach (object obj in array)
            {
                WriteValue(writer, obj, itemType);
            }
        }
Пример #2
0
        private object ReadDictionary(BinaryReader reader, Type memType)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);

            var typeToCreate = memType;
            var genericArgs  = memType.GetGenericArguments();

            var genericBase = typeof(IDictionary <,>);

            if (genericBase == memType.GetGenericTypeDefinition())
            {
                typeToCreate = typeof(Dictionary <,>).MakeGenericType(genericArgs);
            }

            var dic = _typeCache.CreateInstanceDirect(typeToCreate) as IDictionary;

            var keyType = genericArgs[0];
            var valType = genericArgs[1];

            for (int i = 0; i < count; i++)
            {
                var key = ReadMember(reader, keyType);
                var val = ReadMember(reader, valType);
                dic.Add(key, val);
            }
            return(dic);
        }
Пример #3
0
        private void WriteColor(BinaryWriter writer, Color c)
        {
            int argb = c.ToArgb();

            // Int32
            PrimitivesConvertion.WriteVarInt(writer, argb);
        }
Пример #4
0
        private void WriteDataRow(BinaryWriter writer, DataRow row, int columnCount)
        {
            var values = new Dictionary <int, object>();

            for (int i = 0; i < columnCount; i++)
            {
                var val = row[i];
                if (val != null && !Convert.IsDBNull(val))
                {
                    values.Add(i, val);
                }
            }

            // count of non-null columns
            // Int32
            PrimitivesConvertion.WriteVarInt(writer, values.Count);

            foreach (var value in values)
            {
                // Int32
                PrimitivesConvertion.WriteVarInt(writer, value.Key);

                WriteValue(writer, value.Value);
            }
        }
Пример #5
0
        private DateTimeOffset ReadDateTimeOffset(BinaryReader reader)
        {
            var offsetMinutes = PrimitivesConvertion.ReadVarInt16(reader);

            var ticks = PrimitivesConvertion.ReadVarInt64(reader);

            return(new DateTimeOffset(ticks, TimeSpan.FromMinutes(offsetMinutes)));
        }
Пример #6
0
        private void WriteDataset(BinaryWriter writer, DataSet ds)
        {
            // Int32
            PrimitivesConvertion.WriteVarInt(writer, ds.Tables.Count);

            foreach (DataTable table in ds.Tables)
            {
                WriteDataTable(writer, table);
            }
        }
Пример #7
0
        private void WriteCollectionNameValue(BinaryWriter writer, NameValueCollection nameValue)
        {
            // Int32
            PrimitivesConvertion.WriteVarInt(writer, nameValue.Count);

            foreach (string key in nameValue)
            {
                WriteValue(writer, key);
                WriteValue(writer, nameValue[key]);
            }
        }
Пример #8
0
        private object ReadDataset(BinaryReader reader, Type memType)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);
            var ds    = _typeCache.CreateInstance(memType) as DataSet;

            for (int i = 0; i < count; i++)
            {
                var dt = ReadDataTable(reader);
                ds.Tables.Add(dt);
            }
            return(ds);
        }
Пример #9
0
        private object ReadCollectionNameValue(BinaryReader reader, Type type)
        {
            var count     = PrimitivesConvertion.ReadVarInt32(reader);
            var nameValue = (NameValueCollection)_typeCache.CreateInstance(type);
            var strType   = typeof(string);

            for (int i = 0; i < count; i++)
            {
                var name = ReadMember(reader, strType) as string;
                var val  = ReadMember(reader, strType) as string;
                nameValue.Add(name, val);
            }
            return(nameValue);
        }
Пример #10
0
        private void WriteStringDictionary(BinaryWriter writer, IDictionary dic)
        {
            // Int32
            PrimitivesConvertion.WriteVarInt(writer, dic.Count);

            var genericType = dic.GetType().GetGenericArguments();
            var keyType     = GetBoisMemberInfo(typeof(string));
            var valType     = GetBoisMemberInfo(genericType[1]);

            foreach (DictionaryEntry entry in dic)
            {
                WriteValue(writer, entry.Key.ToString(), keyType);
                WriteValue(writer, entry.Value, valType);
            }
        }
Пример #11
0
        private void WriteGuid(BinaryWriter writer, Guid g)
        {
            if (g == Guid.Empty)
            {
                // Int32
                PrimitivesConvertion.WriteVarInt(writer, 0);
                return;
            }

            var data = g.ToByteArray();

            // Int32
            PrimitivesConvertion.WriteVarInt(writer, data.Length);
            writer.Write(data);
        }
Пример #12
0
        private DateTime ReadDateTime(BinaryReader reader)
        {
            var kind  = reader.ReadByte();
            var ticks = PrimitivesConvertion.ReadVarInt64(reader);

            if (ticks == 0L)
            {
                return(DateTime.MinValue);
            }
            if (ticks == 1L)
            {
                return(DateTime.MaxValue);
            }

            return(new DateTime(ticks, (DateTimeKind)kind));
        }
Пример #13
0
        private void WriteDateTimeOffset(BinaryWriter writer, DateTimeOffset dateTimeOffset)
        {
            var   dt     = dateTimeOffset;
            var   offset = dateTimeOffset.Offset;
            short offsetMinutes;

            unchecked
            {
                offsetMinutes = (short)((offset.Hours * 60) + offset.Minutes);
            }
            // int16
            PrimitivesConvertion.WriteVarInt(writer, offsetMinutes);

            // int64
            PrimitivesConvertion.WriteVarInt(writer, dt.Ticks);
        }
Пример #14
0
        private void ReadDataRow(BinaryReader reader, DataRow row, DataColumnCollection cols)
        {
            var itemCount   = PrimitivesConvertion.ReadVarInt32(reader);
            var colCount    = cols.Count;
            var passedIndex = 0;

            while (passedIndex < colCount && passedIndex < itemCount)
            {
                passedIndex++;

                var colIndex = PrimitivesConvertion.ReadVarInt32(reader);
                var col      = cols[colIndex];
                var val      = ReadMember(reader, col.DataType);
                row[col] = val ?? DBNull.Value;
            }
        }
Пример #15
0
        private object ReadStringDictionary(BinaryReader reader, Type memType)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);
            var dic   = _typeCache.CreateInstance(memType) as IDictionary;

            var genericType = memType.GetGenericArguments();
            var keyType     = genericType[0];
            var valType     = genericType[1];

            for (int i = 0; i < count; i++)
            {
                var key = ReadMember(reader, keyType);
                var val = ReadMember(reader, valType);
                dic.Add(key, val);
            }
            return(dic);
        }
Пример #16
0
        private void WriteDataTable(BinaryWriter writer, DataTable table)
        {
            if (string.IsNullOrEmpty(table.TableName))
            {
                table.TableName = "tbl_" + DateTime.Now.Ticks.GetHashCode().ToString();
            }
            WriteString(writer, GetXmlSchema(table));

            // Int32
            PrimitivesConvertion.WriteVarInt(writer, table.Rows.Count);

            var colsCount = table.Columns.Count;

            foreach (DataRow row in table.Rows)
            {
                WriteDataRow(writer, row, colsCount);
            }
        }
Пример #17
0
        private string ReadString(BinaryReader reader)
        {
            int?length = PrimitivesConvertion.ReadVarInt32Nullable(reader);

            if (length == null)
            {
                return(null);
            }
            else if (length == 0)
            {
                return(string.Empty);
            }
            else
            {
                var strBuff = reader.ReadBytes(length.Value);
                return(Encoding.GetString(strBuff, 0, strBuff.Length));
            }
        }
Пример #18
0
 private void WriteString(BinaryWriter writer, string str)
 {
     if (str == null)
     {
         PrimitivesConvertion.WriteVarInt(writer, (int?)null);
     }
     else if (str.Length == 0)
     {
         PrimitivesConvertion.WriteVarInt(writer, (int?)0);
     }
     else
     {
         var strBytes = Encoding.GetBytes(str);
         // Int32
         PrimitivesConvertion.WriteVarInt(writer, (int?)strBytes.Length);
         writer.Write(strBytes);
     }
 }
Пример #19
0
        private object ReadArray(BinaryReader reader, Type type)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);

            var itemType = type.GetElementType();

            if (itemType == null)
            {
                itemType = ReflectionHelper.FindUnderlyingGenericElementType(type);

                if (itemType == null)
                {
                    throw new ArgumentException("Unknown 'Object' array type is not supported.\n" + type);
                }
            }

            IList lst;

            if (type.IsArray)
            {
                var arr = ReflectionHelper.CreateArray(itemType, count);
                lst = arr as IList;

                for (int i = 0; i < count; i++)
                {
                    var val = ReadMember(reader, itemType);
                    lst[i] = val;
                }
                return(arr);
            }
            else
            {
                lst = _typeCache.CreateInstance(type) as IList;

                for (int i = 0; i < count; i++)
                {
                    var val = ReadMember(reader, itemType);
                    lst.Add(val);
                }
                return(lst);
            }
        }
Пример #20
0
        private void WriteArray(BinaryWriter writer, object array)
        {
            var arr = array as Array;

            if (arr == null)
            {
                var enumurable = (IEnumerable)array;

                int count = 0;
                var col   = array as ICollection;
                if (col != null)
                {
                    count = (int)col.Count;
                }
                else
                {
                    foreach (object obj in enumurable)
                    {
                        count++;
                    }
                }

                // Int32
                PrimitivesConvertion.WriteVarInt(writer, count);
                foreach (object obj in enumurable)
                {
                    WriteValue(writer, obj);
                }
            }
            else
            {
                // Int32
                PrimitivesConvertion.WriteVarInt(writer, arr.Length);

                var type     = ReflectionHelper.FindUnderlyingArrayElementType(arr.GetType());
                var bionType = _typeCache.GetTypeInfo(type, true);
                for (int i = 0; i < arr.Length; i++)
                {
                    WriteValue(writer, arr.GetValue(i), bionType);
                }
            }
        }
Пример #21
0
        private DataTable ReadDataTable(BinaryReader reader)
        {
            var dt = _typeCache.CreateInstance(typeof(DataTable)) as DataTable;

            var schema = ReadString(reader);

            //dt.TableName = name;
            SetXmlSchema(dt, schema);

            var cols = dt.Columns;

            var rowCount = PrimitivesConvertion.ReadVarInt32(reader);

            for (int i = 0; i < rowCount; i++)
            {
                var row = dt.Rows.Add();
                ReadDataRow(reader, row, cols);
            }
            return(dt);
        }
Пример #22
0
        private IList ReadIListImpl(BinaryReader reader, Type type)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);

            var listObj = (IList)_typeCache.CreateInstance(type);

            var itemType = type.GetElementType();

            if (itemType == null)
            {
                throw new ArgumentException("Unknown ICollection implementation is not supported.\n" + type.ToString());
            }

            for (int i = 0; i < count; i++)
            {
                var val = ReadMember(reader, itemType);
                listObj.Add(val);
            }

            return(listObj);
        }
Пример #23
0
        private void WriteDictionary(BinaryWriter writer, IDictionary dic)
        {
            // Int32
            PrimitivesConvertion.WriteVarInt(writer, dic.Count);

            var theType      = dic.GetType();
            var genericTypes = ReflectionHelper.FindUnderlyingGenericDictionaryElementType(theType);

            if (genericTypes == null)
            {
                var dictionaryType = ReflectionHelper.FindUnderlyingGenericElementType(theType);
                genericTypes = dictionaryType.GetGenericArguments();
            }

            var keyType = GetBoisMemberInfo(genericTypes[0]);
            var valType = GetBoisMemberInfo(genericTypes[1]);

            foreach (DictionaryEntry entry in dic)
            {
                WriteValue(writer, entry.Key, keyType);
                WriteValue(writer, entry.Value, valType);
            }
        }
Пример #24
0
        private void WriteDateTime(BinaryWriter writer, DateTime dateTime)
        {
            var dt   = dateTime;
            var kind = (byte)dt.Kind;

            if (dateTime == DateTime.MinValue)
            {
                writer.Write(kind);
                // min datetime indicator
                PrimitivesConvertion.WriteVarInt(writer, 0L);
            }
            else if (dateTime == DateTime.MaxValue)
            {
                writer.Write(kind);
                // max datetime indicator
                PrimitivesConvertion.WriteVarInt(writer, 1L);
            }
            else
            {
                writer.Write(kind);
                //Int64
                PrimitivesConvertion.WriteVarInt(writer, dt.Ticks);
            }
        }
Пример #25
0
        private IList ReadGenericList(BinaryReader reader, Type type)
        {
            var count = PrimitivesConvertion.ReadVarInt32(reader);

            var typeToCreate = type;
            var itemType     = type.GetGenericArguments()[0];

            var ilistBase = typeof(IList <>);

            if (ilistBase == type.GetGenericTypeDefinition())
            {
                typeToCreate = typeof(List <>).MakeGenericType(itemType);
            }

            var listObj = (IList)_typeCache.CreateInstanceDirect(typeToCreate);

            for (int i = 0; i < count; i++)
            {
                var val = ReadMember(reader, itemType);
                listObj.Add(val);
            }

            return(listObj);
        }
Пример #26
0
        private object ReadMember(BinaryReader reader, BoisMemberInfo memInfo, Type memType)
        {
            if ((memInfo.IsNullable && memInfo.IsContainerObject) ||
                (memInfo.IsNullable && !memInfo.IsSupportedPrimitive && (!memInfo.IsContainerObject || memInfo.IsStruct)))
            {
                bool isNull = reader.ReadByte() != 0;

                if (isNull)
                {
                    return(null);
                }
            }
            var actualMemberType = memType;

            if (memInfo.IsNullable && memInfo.NullableUnderlyingType != null)
            {
                actualMemberType = memInfo.NullableUnderlyingType;
            }

            switch (memInfo.KnownType)
            {
            case EnBoisKnownType.Unknown:

                if (memInfo.IsContainerObject)
                {
                    return(ReadObject(reader, actualMemberType));
                }
                else if (memInfo.IsStringDictionary)
                {
                    return(ReadStringDictionary(reader, actualMemberType));
                }
                else if (memInfo.IsDictionary)
                {
                    return(ReadDictionary(reader, actualMemberType));
                }
                else if (memInfo.IsCollection)
                {
                    if (memInfo.IsGeneric)
                    {
                        return(ReadGenericList(reader, actualMemberType));
                    }
                    return(ReadArray(reader, actualMemberType));
                }
                else if (memInfo.IsArray)
                {
                    return(ReadArray(reader, actualMemberType));
                }

                break;

            case EnBoisKnownType.Int16:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt16Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt16(reader));

            case EnBoisKnownType.UInt16:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt16Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt16(reader));

            case EnBoisKnownType.Int32:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt32Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt32(reader));

            case EnBoisKnownType.Int64:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarInt64Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarInt64(reader));

            case EnBoisKnownType.UInt64:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt64Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt64(reader));

            case EnBoisKnownType.UInt32:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarUInt32Nullable(reader));
                }
                return(PrimitivesConvertion.ReadVarUInt32(reader));

            case EnBoisKnownType.Double:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarDoubleNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarDouble(reader));

            case EnBoisKnownType.Decimal:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarDecimalNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarDecimal(reader));

            case EnBoisKnownType.Single:
                if (memInfo.IsNullable)
                {
                    return(PrimitivesConvertion.ReadVarSingleNullable(reader));
                }
                return(PrimitivesConvertion.ReadVarSingle(reader));

            case EnBoisKnownType.Byte:
                return(reader.ReadByte());

            case EnBoisKnownType.SByte:
                return(reader.ReadSByte());

            case EnBoisKnownType.ByteArray:
                return(ReadBytes(reader));

            case EnBoisKnownType.String:
                return(ReadString(reader));

            case EnBoisKnownType.Char:
                var charByte = reader.ReadUInt16();
                return((char)charByte);

            case EnBoisKnownType.Bool:
                return(ReadBoolean(reader));

            case EnBoisKnownType.Enum:
                return(ReadEnum(reader, actualMemberType));

            case EnBoisKnownType.DateTime:
                return(ReadDateTime(reader));

            case EnBoisKnownType.DateTimeOffset:
                return(ReadDateTimeOffset(reader));

            case EnBoisKnownType.TimeSpan:
                return(ReadTimeSpan(reader));

#if !SILVERLIGHT && DotNet
            case EnBoisKnownType.DataSet:
                return(ReadDataset(reader, actualMemberType));

            case EnBoisKnownType.DataTable:
                return(ReadDataTable(reader));
#endif
#if DotNet || DotNetCore || DotNetStandard
            case EnBoisKnownType.NameValueColl:
                return(ReadCollectionNameValue(reader, actualMemberType));

            case EnBoisKnownType.Color:
                return(ReadColor(reader));

            case EnBoisKnownType.DbNull:
                return(DBNull.Value);
#endif

            case EnBoisKnownType.Version:
                return(ReadVersion(reader));

            case EnBoisKnownType.Guid:
                return(ReadGuid(reader));

            case EnBoisKnownType.Uri:
                return(ReadUri(reader));

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }
Пример #27
0
 private void WriteTimeSpan(BinaryWriter writer, TimeSpan timeSpan)
 {
     // Int64
     PrimitivesConvertion.WriteVarInt(writer, timeSpan.Ticks);
 }
Пример #28
0
        void WriteValue(BinaryWriter writer, BoisMemberInfo boisMemInfo, object value)
        {
            if (!boisMemInfo.IsSupportedPrimitive && !boisMemInfo.IsContainerObject)
            {
                if (value == null)
                {
                    WriteNullableType(writer, true);
                    return;
                }
                else if (boisMemInfo.IsNullable)
                {
                    WriteNullableType(writer, false);
                }
            }

            switch (boisMemInfo.KnownType)
            {
            case EnBoisKnownType.Unknown:

                if (boisMemInfo.IsContainerObject)
                {
                    WriteObject(writer, boisMemInfo, value);
                }
                else if (boisMemInfo.IsStringDictionary)
                {
                    WriteStringDictionary(writer, value as IDictionary);
                }
                else if (boisMemInfo.IsDictionary)
                {
                    WriteDictionary(writer, value as IDictionary);
                }
                else if (boisMemInfo.IsCollection || boisMemInfo.IsArray)
                {
                    if (boisMemInfo.IsGeneric)
                    {
                        WriteGenericList(writer, value as IEnumerable);
                    }
                    else
                    {
                        WriteArray(writer, value);
                    }
                }
                break;

            case EnBoisKnownType.Int16:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (short?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (short)value);
                }
                break;

            case EnBoisKnownType.UInt16:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (ushort?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (ushort)value);
                }
                break;

            case EnBoisKnownType.Int32:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (int?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (int)value);
                }

                break;

            case EnBoisKnownType.Int64:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (long?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (long)value);
                }
                break;

            case EnBoisKnownType.UInt64:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (ulong?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (ulong)value);
                }
                break;

            case EnBoisKnownType.UInt32:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarInt(writer, (uint?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarInt(writer, (uint)value);
                }
                break;

            case EnBoisKnownType.Double:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (double?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (double)value);
                }
                break;

            case EnBoisKnownType.Decimal:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (decimal?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (decimal)value);
                }
                break;

            case EnBoisKnownType.Single:
                if (value == null || boisMemInfo.IsNullable)
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (float?)value);
                }
                else
                {
                    PrimitivesConvertion.WriteVarDecimal(writer, (float)value);
                }
                break;

            case EnBoisKnownType.Byte:
                writer.Write((byte)value);
                break;

            case EnBoisKnownType.SByte:
                writer.Write((sbyte)value);
                break;

            case EnBoisKnownType.ByteArray:
                WriteBytes(writer, (byte[])value);
                break;

            case EnBoisKnownType.String:
                WriteString(writer, value as string);
                break;

            case EnBoisKnownType.Char:
                writer.Write((ushort)((char)value));
                break;

            case EnBoisKnownType.Bool:
                writer.Write((byte)(((bool)value) ? 1 : 0));
                break;

            case EnBoisKnownType.Enum:
                WriteEnum(writer, (Enum)value);
                break;

            case EnBoisKnownType.DateTime:
                WriteDateTime(writer, (DateTime)value);
                break;

            case EnBoisKnownType.DateTimeOffset:
                WriteDateTimeOffset(writer, (DateTimeOffset)value);
                break;

            case EnBoisKnownType.TimeSpan:
                WriteTimeSpan(writer, (TimeSpan)value);
                break;

#if !SILVERLIGHT && DotNet
            case EnBoisKnownType.DataSet:
                WriteDataset(writer, value as DataSet);
                break;

            case EnBoisKnownType.DataTable:
                WriteDataTable(writer, value as DataTable);
                break;
#endif
#if DotNet || DotNetCore || DotNetStandard
            case EnBoisKnownType.NameValueColl:
                WriteCollectionNameValue(writer, value as NameValueCollection);
                break;

            case EnBoisKnownType.Color:
                WriteColor(writer, (Color)value);
                break;
#endif


            case EnBoisKnownType.Version:
                WriteVersion(writer, value as Version);
                break;

            case EnBoisKnownType.DbNull:
                // Do not write anything, it is already written as Nullable object. //WriteNullableType(true);
                break;

            case EnBoisKnownType.Guid:
                WriteGuid(writer, (Guid)value);
                break;

            case EnBoisKnownType.Uri:
                WriteUri(writer, value as Uri);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #29
0
 private void WriteBytes(BinaryWriter writer, byte[] bytes)
 {
     // Int32
     PrimitivesConvertion.WriteVarInt(writer, bytes.Length);
     writer.Write(bytes);
 }
Пример #30
0
 private void WriteEnum(BinaryWriter writer, Enum e)
 {
     // Int32
     PrimitivesConvertion.WriteVarInt(writer, (int)((object)e));
 }