TryGet() public method

Tries to get a value by its key.
public TryGet ( LightningDatabase db, byte key, byte &value ) : bool
db LightningDatabase Database.
key byte Key byte array.
value byte Value byte array if exists.
return bool
        public static bool TryGetBy <TKey>(this LightningTransaction txn, LightningDatabase db, TKey key, out GetByOperation value)
        {
            byte[] valueBytes;

            var keyBytes = db.ToBytes(key);
            var result   = txn.TryGet(db, keyBytes, out valueBytes);

            value = result
                ? new GetByOperation(db, valueBytes)
                : null;

            return(result);
        }
Example #2
0
 /// <summary>
 /// Tries to get a value by its key.
 /// </summary>
 /// <param name="txn">A transaction</param>
 /// <param name="key">Key byte array.</param>
 /// <param name="value">Value byte array if exists.</param>
 /// <returns>True if key exists, false if not.</returns>
 public static bool TryGet(this LightningTransaction txn, byte[] key, out byte[] value)
 {
     return(txn.TryGet(key, out value));
 }
Example #3
0
 /// <summary>
 /// Tries obtaining a value by key, converting it to a concrete type
 /// </summary>
 /// <typeparam name="TKey">Type of a key.</typeparam>
 /// <typeparam name="TValue">Type to convert value to.</typeparam>
 /// <param name="txn">A transaction.</param>
 /// <param name="key">Key.</param>
 /// <param name="value">Obtained and converted value if successful.</param>
 /// <returns>Returns true if key-value pair exists in database or false if not.</returns>
 public static bool TryGet <TKey, TValue>(this LightningTransaction txn, TKey key, out TValue value)
 {
     return(txn.TryGet(txn.OpenDatabase(), key, out value));
 }