PeterO.Cbor.CBORObject.AsUInt64 C# (CSharp) Method

AsUInt64() private method

private AsUInt64 ( ) : ulong
return ulong
        public ulong AsUInt64()
        {
            ICBORNumber cn = NumberInterfaces[this.ItemType];
              if (cn == null) {
            throw new InvalidOperationException("Not a number type");
              }
              // TODO: When this library uses PeterO.Numbers later than 0.2, use an
              // operator
              EInteger bigint = cn.AsEInteger(this.ThisItem);
              if (bigint.Sign < 0 || bigint.GetSignedBitLength() > 64) {
            throw new OverflowException("This object's value is out of range");
              }
              byte[] data = bigint.ToBytes(true);
              var a = 0;
              var b = 0;
              for (var i = 0; i < Math.Min(4, data.Length); ++i) {
            a |= (((int)data[i]) & 0xff) << (i * 8);
              }
              for (int i = 4; i < Math.Min(8, data.Length); ++i) {
            b |= (((int)data[i]) & 0xff) << ((i - 4) * 8);
              }
              unchecked
              {
            var ret = (ulong)a;
            ret &= 0xffffffffL;
            var retb = (ulong)b;
            retb &= 0xffffffffL;
            ret |= retb << 32;
            return ret;
              }
        }

Usage Example

コード例 #1
0
 private static object TypeToIntegerObject(CBORObject objThis, Type t)
 {
     if (t.Equals(typeof(int)))
     {
         return(objThis.AsInt32());
     }
     if (t.Equals(typeof(short)))
     {
         return(objThis.AsInt16());
     }
     if (t.Equals(typeof(ushort)))
     {
         return(objThis.AsUInt16());
     }
     if (t.Equals(typeof(byte)))
     {
         return(objThis.AsByte());
     }
     if (t.Equals(typeof(sbyte)))
     {
         return(objThis.AsSByte());
     }
     if (t.Equals(typeof(long)))
     {
         return(objThis.AsInt64());
     }
     if (t.Equals(typeof(uint)))
     {
         return(objThis.AsUInt32());
     }
     if (t.Equals(typeof(ulong)))
     {
         return(objThis.AsUInt64());
     }
     throw new CBORException("Type not supported");
 }
All Usage Examples Of PeterO.Cbor.CBORObject::AsUInt64