public TryGet ( |
||
db | Database. | |
key | byte | Key byte array. |
value | byte | Value byte array if exists. |
리턴 | 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); }
/// <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)); }
/// <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)); }