Exemplo n.º 1
0
        protected IConvertible ReadIntValue(BinaryReader reader, StructInstance instance)
        {
            Expression expr = GetExpressionAttribute("value");

            if (expr != null)
            {
                return(expr.EvaluateInt(instance));
            }

            if (_structDef.IsReverseByteOrder())
            {
                reader = new ReverseByteOrderReader(reader.BaseStream);
            }

            IConvertible value;

            switch (_size)
            {
            case 1:
                value = _unsigned ? (IConvertible)reader.ReadByte() : reader.ReadSByte();
                break;

            case 2:
                value = _unsigned ? (IConvertible)reader.ReadUInt16() : reader.ReadInt16();
                break;

            case 4:
                value = _unsigned ? (IConvertible)reader.ReadUInt32() : reader.ReadInt32();
                break;

            case 8:
                value = _unsigned ? (IConvertible)reader.ReadUInt64() : reader.ReadInt64();
                break;

            default:
                throw new Exception("Unsupported integer size " + _size);
            }
            return(value);
        }
Exemplo n.º 2
0
        protected IConvertible ReadIntValue(BinaryReader reader, StructInstance instance)
        {
            Expression expr = GetExpressionAttribute("value");
            if (expr != null)
            {
                return expr.EvaluateInt(instance);
            }

            if (_structDef.IsReverseByteOrder())
                reader = new ReverseByteOrderReader(reader.BaseStream);

            IConvertible value;
            switch (_size)
            {
                case 1:
                    value = _unsigned ? (IConvertible)reader.ReadByte() : reader.ReadSByte();
                    break;

                case 2:
                    value = _unsigned ? (IConvertible)reader.ReadUInt16() : reader.ReadInt16();
                    break;

                case 4:
                    value = _unsigned ? (IConvertible)reader.ReadUInt32() : reader.ReadInt32();
                    break;

                case 8:
                    value = _unsigned ? (IConvertible) reader.ReadUInt64() : reader.ReadInt64();
                    break;

                default:
                    throw new Exception("Unsupported integer size " + _size);
            }
            return value;
        }