/// <summary> /// Stores `_key` field value. /// </summary> /// <exception cref="ArgumentException">Specified key value has invalid format.</exception> public static Dictionary <string, object> Key(this Dictionary <string, object> dictionary, string key) { if (!ADocument.IsKey(key)) { throw new ArgumentException("Specified key value (" + key + ") has invalid format."); } SetFieldValue(dictionary, "_key", key); return(dictionary); }
/// <summary> /// Retrieves value of `_key` field. If the field is missing or has invalid format null value is returned. /// </summary> public static string Key(this Dictionary <string, object> dictionary) { string key; try { key = String(dictionary, "_key"); if (!ADocument.IsKey(key)) { key = null; } } catch (Exception) { key = null; } return(key); }
/// <summary> /// Checks if specified field path has valid document key value. /// </summary> public static bool IsKey(this Dictionary <string, object> dictionary, string fieldPath) { var isValid = false; try { var fieldValue = GetFieldValue(dictionary, fieldPath); if (fieldValue is string) { return(ADocument.IsKey((string)fieldValue)); } } catch (Exception) { isValid = false; } return(isValid); }