示例#1
0
 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;
                 }
             }
         }
     }
 }