Ejemplo n.º 1
0
        /// <summary>
        /// Gets the <see cref="Maybe{TResult}"/> of the projection function <paramref name="func"/>.
        /// </summary>
        /// <typeparam name="TResult">The type of the projected result.</typeparam>
        /// <param name="func">The projection function.</param>
        /// <returns>The projected maybe.</returns>
        public Maybe <TResult> Some <TResult>(Func <T, TResult> func)
            where TResult : class
        {
            MaybeUtils.CheckArgumentNotNull(func, nameof(func));

            var maybe = Maybe.None <TResult>();

            this.Do(x => maybe = Maybe.Some(func(x)));

            return(maybe);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the <see cref="MaybeStruct{TResult}"/> of the projection function <paramref name="func"/>.
        /// </summary>
        /// <typeparam name="TResult">The type of the projected result.</typeparam>
        /// <param name="func">The projection function.</param>
        /// <returns>The projected maybe.</returns>
        public MaybeStruct <TResult> SomeStruct <TResult>(Func <T, MaybeStruct <TResult> > func)
            where TResult : struct
        {
            MaybeUtils.CheckArgumentNotNull(func, nameof(func));

            var maybe = Maybe.NoneStruct <TResult>();

            this.Do(x => maybe = func(x));

            return(maybe);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes <paramref name="doAction"/> if value is not null.
        /// </summary>
        /// <param name="doAction">The action which is performed if maybe is not none.</param>
        /// <returns>The none case.</returns>
        public NoneCase Do(Action <T> doAction)
        {
            MaybeUtils.CheckArgumentNotNull(doAction, nameof(doAction));

            if (this.value != null)
            {
                doAction(this.value);
                return(new NoneCase(false));
            }

            return(new NoneCase(true));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets <paramref name="data"/> to serialization info.
        /// </summary>
        /// <typeparam name="T">The data's type.</typeparam>
        /// <param name="info">The serialization info.</param>
        /// <param name="key">The data's key.</param>
        /// <param name="data">The data.</param>
        internal static void SetData <T>(SerializationInfo info, string key, T data)
        {
            MaybeUtils.CheckArgumentNotNull(info, nameof(info));

            info.AddValue(key, data, typeof(T));
        }