Example #1
0
        /// <summary>
        /// Attempts to get the value of a Try* method with an out parameter, for example <see cref="Dictionary{TKey,TValue}.TryGetValue" /> or <see cref="ConcurrentQueue{T}.TryDequeue" />.
        /// </summary>
        /// <typeparam name="T">The type of the source object.</typeparam>
        /// <typeparam name="TOut">The type the out parameter.</typeparam>
        /// <param name="source">The source object exposing the Try* method.</param>
        /// <param name="tryTryGetValue">A delegate to call the Try* method.</param>
        /// <returns></returns>
        public static Maybe <TOut> Out <T, TOut>(this T source, TryGetOutParameter <T, TOut> tryTryGetValue)
        {
            TOut result;

            return(tryTryGetValue(source, out result)
                       ? Maybe <TOut> .Yes(result)
                       : Maybe <TOut> .No());
        }
Example #2
0
        /// <summary>
        /// Attempts to get the value of a Try* method with an out parameter, for example <see cref="Dictionary{TKey,TValue}.TryGetValue" /> or <see cref="ConcurrentQueue{T}.TryDequeue" />.
        /// </summary>
        /// <typeparam name="T">The type of the source object.</typeparam>
        /// <typeparam name="TOut">The type the out parameter.</typeparam>
        /// <param name="source">The source object exposing the Try* method.</param>
        /// <param name="tryTryGetValue">A delegate to call the Try* method.</param>
        /// <returns></returns>
        public static Maybe <TOut> Out <T, TOut>(this T source, TryGetOutParameter <T, TOut> tryTryGetValue)
        {
            TOut result;

            if (tryTryGetValue(source, out result))
            {
                return(Recipes.Maybe <TOut> .Yes(result));
            }

            return(Recipes.Maybe <TOut> .No());
        }