/// <summary>
        /// Attempts to get the entity from the cache.
        /// </summary>
        /// <param name="cache">The cache to perform the operation on.</param>
        /// <param name="key">The JSON API entity key to return the value for.</param>
        /// <param name="value">The value that was associated with the given key.</param>
        /// <returns>true if the an entity was found for the key, false if not.</returns>
        internal static bool TryGetValue(this IJsonApiEntityCache cache, JsonApiEntityKey key, out object value)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            return(cache.TryGetValue(key.Type, key.Id, out value));
        }
예제 #2
0
        /// <summary>
        /// Attempts to get the entity from the cache.
        /// </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 locate.</param>
        /// <param name="value">The entity that is associated with the given type and ID, otherwise the default value is returned.</param>
        /// <returns>true if the object that implements <see cref="T:Hypermedia.JsonApi.IJsonApiEntityCache" /> contains an element with the specified key; otherwise, false.</returns>
        public static bool TryGetValue(this IJsonApiEntityCache cache, JsonObject key, out object value)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            string type;
            string id;

            if (TryCreateKey(key, out type, out id) == false)
            {
                value = null;
                return(false);
            }

            return(cache.TryGetValue(type, id, out value));
        }