public static void Serialize(StreamPropertyType propId, object value, byte[] buffer, ref int offset) { if (buffer == null || offset > buffer.Length) { throw new ArgumentException("buffer"); } offset += ExBitConverter.Write((short)propId, buffer, offset); PropertyStreamWriter.WriteValue(propId, value, buffer, ref offset); }
private static void WriteMultiValuedProperty <T>(StreamPropertyType propId, MultiValuedProperty <T> list, byte[] buffer, ref int offset) { int num = (list != null) ? list.Count : 0; offset += ExBitConverter.Write(num, buffer, offset); for (int i = 0; i < num; i++) { PropertyStreamWriter.WriteValue(propId & ~StreamPropertyType.MultiValuedProperty, list[i], buffer, ref offset); } }
private static void WriteArray <T>(StreamPropertyType propId, T[] array, byte[] buffer, ref int offset) { int num = (array != null) ? array.Length : 0; offset += ExBitConverter.Write(num, buffer, offset); for (int i = 0; i < num; i++) { PropertyStreamWriter.WriteValue(propId & ~StreamPropertyType.Array, array[i], buffer, ref offset); } }
public static void WriteValue(StreamPropertyType propId, object value, byte[] buffer, ref int offset) { if (buffer == null || offset > buffer.Length) { throw new ArgumentException("buffer"); } if (propId <= (StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List)) { switch (propId) { case StreamPropertyType.Null: return; case StreamPropertyType.Bool: buffer[offset++] = (((bool)value) ? 1 : 0); return; case StreamPropertyType.Byte: buffer[offset++] = (byte)value; return; case StreamPropertyType.SByte: { sbyte b = (sbyte)value; buffer[offset++] = (byte)b; return; } case StreamPropertyType.Int16: offset += ExBitConverter.Write((short)value, buffer, offset); return; case StreamPropertyType.UInt16: offset += ExBitConverter.Write((ushort)value, buffer, offset); return; case StreamPropertyType.Int32: offset += ExBitConverter.Write((int)value, buffer, offset); return; case StreamPropertyType.UInt32: offset += ExBitConverter.Write((uint)value, buffer, offset); return; case StreamPropertyType.Int64: offset += ExBitConverter.Write((long)value, buffer, offset); return; case StreamPropertyType.UInt64: offset += ExBitConverter.Write((ulong)value, buffer, offset); return; case StreamPropertyType.Single: offset += ExBitConverter.Write((float)value, buffer, offset); return; case StreamPropertyType.Double: offset += ExBitConverter.Write((double)value, buffer, offset); return; case StreamPropertyType.Decimal: { decimal d = (decimal)value; int[] bits = decimal.GetBits(d); for (int i = 0; i < bits.Length; i++) { offset += ExBitConverter.Write(bits[i], buffer, offset); } return; } case StreamPropertyType.Char: value = new char[] { (char)value }; break; case StreamPropertyType.String: { int num = 0; string text = (string)value; if (!string.IsNullOrEmpty(text)) { num = Encoding.UTF8.GetBytes(text, 0, text.Length, buffer, offset + 4); } offset += ExBitConverter.Write(num, buffer, offset); offset += num; return; } case StreamPropertyType.DateTime: { DateTime dateTime = (DateTime)value; offset += ExBitConverter.Write(dateTime.ToFileTimeUtc(), buffer, offset); return; } case StreamPropertyType.Guid: offset += ExBitConverter.Write((Guid)value, buffer, offset); return; case StreamPropertyType.IPAddress: { IPvxAddress pvxAddress = new IPvxAddress((value == null) ? IPAddress.None : ((IPAddress)value)); long value2 = (long)((ulong)((uint)pvxAddress)); offset += ExBitConverter.Write(value2, buffer, offset); value2 = (long)((ulong)((uint)(pvxAddress >> 64))); offset += ExBitConverter.Write(value2, buffer, offset); return; } case StreamPropertyType.IPEndPoint: { if (value == null) { PropertyStreamWriter.WriteValue(StreamPropertyType.IPAddress, IPAddress.None, buffer, ref offset); PropertyStreamWriter.WriteValue(StreamPropertyType.UInt16, 0, buffer, ref offset); return; } IPEndPoint ipendPoint = (IPEndPoint)value; PropertyStreamWriter.WriteValue(StreamPropertyType.IPAddress, ipendPoint.Address, buffer, ref offset); PropertyStreamWriter.WriteValue(StreamPropertyType.UInt16, (ushort)ipendPoint.Port, buffer, ref offset); return; } case StreamPropertyType.RoutingAddress: case StreamPropertyType.ADObjectId: case StreamPropertyType.RecipientType: case StreamPropertyType.ADObjectIdUTF8: case StreamPropertyType.ADObjectIdWithString: case StreamPropertyType.ProxyAddress: goto IL_808; default: switch (propId) { case StreamPropertyType.Bool | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <bool>(propId, (bool[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array: { byte[] array = (byte[])value; offset += ExBitConverter.Write(array.Length, buffer, offset); if (array.Length != 0) { Array.Copy(array, 0, buffer, offset, array.Length); offset += array.Length; return; } return; } case StreamPropertyType.SByte | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <sbyte>(propId, (sbyte[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <short>(propId, (short[])value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <ushort>(propId, (ushort[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <int>(propId, (int[])value, buffer, ref offset); return; case StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <uint>(propId, (uint[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <long>(propId, (long[])value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <ulong>(propId, (ulong[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <float>(propId, (float[])value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <double>(propId, (double[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <decimal>(propId, (decimal[])value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: break; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <string>(propId, (string[])value, buffer, ref offset); return; case StreamPropertyType.DateTime | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <DateTime>(propId, (DateTime[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <Guid>(propId, (Guid[])value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <IPAddress>(propId, (IPAddress[])value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array: PropertyStreamWriter.WriteArray <IPEndPoint>(propId, (IPEndPoint[])value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array: case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array: case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array: goto IL_808; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array: return; default: switch (propId) { case StreamPropertyType.Bool | StreamPropertyType.List: PropertyStreamWriter.WriteList <bool>(propId, (List <bool>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.List: PropertyStreamWriter.WriteList <byte>(propId, (List <byte>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.List: PropertyStreamWriter.WriteList <sbyte>(propId, (List <sbyte>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.List: PropertyStreamWriter.WriteList <short>(propId, (List <short>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List: PropertyStreamWriter.WriteList <ushort>(propId, (List <ushort>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List: PropertyStreamWriter.WriteList <int>(propId, (List <int>)value, buffer, ref offset); return; case StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <uint>(propId, (List <uint>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <long>(propId, (List <long>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <ulong>(propId, (List <ulong>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <float>(propId, (List <float>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <double>(propId, (List <double>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <decimal>(propId, (List <decimal>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: { char[] value3 = (value != null) ? ((List <char>)value).ToArray() : null; PropertyStreamWriter.WriteValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array, value3, buffer, ref offset); return; } case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List: PropertyStreamWriter.WriteList <string>(propId, (List <string>)value, buffer, ref offset); return; case StreamPropertyType.DateTime | StreamPropertyType.List: PropertyStreamWriter.WriteList <DateTime>(propId, (List <DateTime>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.List: PropertyStreamWriter.WriteList <Guid>(propId, (List <Guid>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List: PropertyStreamWriter.WriteList <IPAddress>(propId, (List <IPAddress>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List: PropertyStreamWriter.WriteList <IPEndPoint>(propId, (List <IPEndPoint>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List: case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List: case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List: goto IL_808; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List: return; default: return; } break; } break; } int num2 = 0; if (value != null) { char[] array2 = (char[])value; if (array2.Length != 0) { num2 = Encoding.UTF8.GetBytes(array2, 0, array2.Length, buffer, offset + 4); } } offset += ExBitConverter.Write(num2, buffer, offset); offset += num2; return; } if (propId == (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.List)) { PropertyStreamWriter.WriteList <byte[]>(propId, (List <byte[]>)value, buffer, ref offset); return; } switch (propId) { case StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <bool>(propId, (MultiValuedProperty <bool>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <byte>(propId, (MultiValuedProperty <byte>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <sbyte>(propId, (MultiValuedProperty <sbyte>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <short>(propId, (MultiValuedProperty <short>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <ushort>(propId, (MultiValuedProperty <ushort>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <int>(propId, (MultiValuedProperty <int>)value, buffer, ref offset); return; case StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <uint>(propId, (MultiValuedProperty <uint>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <long>(propId, (MultiValuedProperty <long>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <ulong>(propId, (MultiValuedProperty <ulong>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <float>(propId, (MultiValuedProperty <float>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <double>(propId, (MultiValuedProperty <double>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <decimal>(propId, (MultiValuedProperty <decimal>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: { char[] value4 = (value != null) ? ((MultiValuedProperty <char>)value).ToArray() : null; PropertyStreamWriter.WriteValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array, value4, buffer, ref offset); return; } case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <string>(propId, (MultiValuedProperty <string>)value, buffer, ref offset); return; case StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <DateTime>(propId, (MultiValuedProperty <DateTime>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <Guid>(propId, (MultiValuedProperty <Guid>)value, buffer, ref offset); return; case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <IPAddress>(propId, (MultiValuedProperty <IPAddress>)value, buffer, ref offset); return; case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: PropertyStreamWriter.WriteMultiValuedProperty <IPEndPoint>(propId, (MultiValuedProperty <IPEndPoint>)value, buffer, ref offset); return; case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: break; case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty: return; default: if (propId != (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.MultiValuedProperty)) { return; } PropertyStreamWriter.WriteMultiValuedProperty <byte[]>(propId, (MultiValuedProperty <byte[]>)value, buffer, ref offset); return; } IL_808: throw new InvalidOperationException(string.Format("Dont know how to handle type {0}", propId)); }