public byte[] Encode(object value, uint numberOfBytesArray)
        {
            BigInteger bigInt;

            var stringValue = value as string;

            if (stringValue != null)
            {
                bigInt = intTypeDecoder.Decode <BigInteger>(stringValue);
            }
            else if (value is BigInteger)
            {
                bigInt = (BigInteger)value;
            }
            else if (value.IsNumber())
            {
                bigInt = BigInteger.Parse(value.ToString());
            }
            else if (value is Enum)
            {
                bigInt = (BigInteger)(int)value;
            }
            else
            {
                throw new Exception($"Invalid value for type '{this}'. Value: {value ?? "null"}, ValueType: ({value?.GetType()})");
            }
            return(EncodeInt(bigInt, numberOfBytesArray));
        }
Beispiel #2
0
        public byte[] Encode(object value)
        {
            BigInteger bigInt;

            var stringValue = value as string;

            if (stringValue != null)
            {
                bigInt = intTypeDecoder.Decode <BigInteger>(stringValue);
            }
            else if (value is BigInteger)
            {
                bigInt = (BigInteger)value;
            }
            else if (value.IsNumber())
            {
                bigInt = BigInteger.Parse(value.ToString());
            }
            else if (value is Enum)
            {
                bigInt = (BigInteger)(int)value;
            }
            else
            {
                throw new Exception("Invalid value for type '" + this + "': " + value + " (" + value.GetType() + ")");
            }
            return(EncodeInt(bigInt));
        }