private void ReadImperativeBits(PackedBitReader reader, object value, IEnumerable <PropertyInfo> properties, Func <PropertyInfo, BitPair> getBitPair) { foreach (PropertyInfo prop in properties) { if (prop.PropertyType == typeof(bool)) { prop.SetValue(value, reader.ReadBool(), null); } else { BitPair read = getBitPair(prop); int bitRange = read.Count; if (read.Signed) { if (prop.PropertyType == typeof(sbyte)) { prop.SetValue(value, reader.ReadSignedInt8(bitRange), null); } else if (prop.PropertyType == typeof(short)) { prop.SetValue(value, reader.ReadSignedInt16(bitRange), null); } else if (prop.PropertyType == typeof(int)) { prop.SetValue(value, reader.ReadSignedInt32(bitRange), null); } else if (prop.PropertyType == typeof(long)) { prop.SetValue(value, reader.ReadSignedInt64(bitRange), null); } else { throw CodePath.Unreachable; } } else { if (prop.PropertyType == typeof(sbyte)) { prop.SetValue(value, reader.ReadInt8(bitRange), null); } else if (prop.PropertyType == typeof(short)) { prop.SetValue(value, reader.ReadInt16(bitRange), null); } else if (prop.PropertyType == typeof(int)) { prop.SetValue(value, reader.ReadInt32(bitRange), null); } else if (prop.PropertyType == typeof(long)) { prop.SetValue(value, reader.ReadInt64(bitRange), null); } else if (prop.PropertyType == typeof(byte)) { prop.SetValue(value, reader.ReadUInt8(bitRange), null); } else if (prop.PropertyType == typeof(ushort)) { prop.SetValue(value, reader.ReadUInt16(bitRange), null); } else if (prop.PropertyType == typeof(uint)) { prop.SetValue(value, reader.ReadUInt32(bitRange), null); } else if (prop.PropertyType == typeof(ulong)) { prop.SetValue(value, reader.ReadUInt64(bitRange), null); } else { throw CodePath.Unreachable; } } } } }
private void WriteImperativeBits(PackedBitWriter writer, object value, IEnumerable <PropertyInfo> properties, Func <PropertyInfo, BitPair> getBitPair) { foreach (PropertyInfo prop in properties) { if (prop.PropertyType == typeof(bool)) { writer.Write((bool)prop.GetValue(value, null)); } else { BitPair write = getBitPair(prop); int bitRange = write.Count; if (write.Signed) { if (prop.PropertyType == typeof(sbyte)) { writer.WriteSigned(bitRange, (sbyte)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(short)) { writer.WriteSigned(bitRange, (short)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(int)) { writer.WriteSigned(bitRange, (int)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(long)) { writer.WriteSigned(bitRange, (long)prop.GetValue(value, null)); } else { throw CodePath.Unreachable; } } else { if (prop.PropertyType == typeof(sbyte)) { writer.Write(bitRange, (sbyte)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(short)) { writer.Write(bitRange, (short)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(int)) { writer.Write(bitRange, (int)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(long)) { writer.Write(bitRange, (long)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(byte)) { writer.Write(bitRange, (byte)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(ushort)) { writer.Write(bitRange, (ushort)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(uint)) { writer.Write(bitRange, (uint)prop.GetValue(value, null)); } else if (prop.PropertyType == typeof(ulong)) { writer.Write(bitRange, (ulong)prop.GetValue(value, null)); } else { throw CodePath.Unreachable; } } } } }