/// <summary> /// Attempts to add an element with the provided key and value to the <see cref="T:Hypermedia.JsonApi.IJsonApiEntityCache" />. /// </summary> /// <param name="cache">The cache to perform the operation on.</param> /// <param name="key">The JSON API entity key that is assign to the value.</param> /// <param name="value">The object to use as the value of the element to add.</param> /// <returns>true if the entity could be added, false if it could not be added.</returns> internal static bool TryAdd(this IJsonApiEntityCache cache, JsonApiEntityKey key, object value) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } return(cache.TryAdd(key.Type, key.Id, value)); }
/// <summary> /// Attempts to adds an entity to the <see cref="T:Hypermedia.JsonApi.IJsonApiEntityCache" />. /// </summary> /// <param name="cache">The cache to add the entity to.</param> /// <param name="key">The item that defines the key for the entity to add.</param> /// <param name="value">The object to use as the value of the element to add.</param> /// <returns>true if the entity could be added, false if it could not be added.</returns> public static bool TryAdd(this IJsonApiEntityCache cache, JsonObject key, object value) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } string type; string id; if (TryCreateKey(key, out type, out id) == false) { return(false); } return(cache.TryAdd(type, id, value)); }