internal ExpressionStarter(bool defaultExpression) { var expression = defaultExpression ? (_ => true) : (Expression <Func <T, bool> >)(_ => false); DefaultExpression = expression; _predicate = OptionalBuilder.Empty <Expression <Func <T, bool> > >(); }
/// <summary> /// Converts the current instance to the specific type if possible. /// Otherwise returns an empty optional if the current is empty or an exception optional if the current is an exception. /// </summary> /// <typeparam name="TU">The type to convert to.</typeparam> public Optional <TU> ToOptional <TU>() { if (IsValue() && InternalValue is TU target) { return(target); } return(IsException() ? OptionalBuilder.Exception <TU>(InternalException) : OptionalBuilder.Empty <TU>()); }
/// <summary> /// Initializes a new instance of <see cref="Invocation"/> with the arguments needed for invocation. /// </summary> /// <param name="targetMethod">The target method.</param> /// <param name="targetInstance">The target instance being called.</param> /// <param name="argsValue">Arguments for the method, if necessary.</param> /// <exception cref="ArgumentNullException">The <paramref name="targetMethod"/> is null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="targetInstance"/> is null.</exception> internal Invocation(MethodInfo targetMethod, object targetInstance, params object[] argsValue) { _method = targetMethod ?? throw new ArgumentNullException(nameof(targetMethod)); _instance = targetInstance ?? throw new ArgumentNullException(nameof(targetInstance)); ReturnType = _method.ReturnType; ReturnValue = OptionalBuilder.Empty <object>(); Exception = OptionalBuilder.Empty <Exception>(); Arguments = GetParametersFromMethod(_method, argsValue).ToArray(); }
internal ExpressionExpander() { _replaceVars = OptionalBuilder.Empty <Dictionary <ParameterExpression, Expression> >(); }
/// <summary> /// Returns an optional that contains the value if that value matches the predicate. /// Otherwise returns an empty optional. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="source">The value to act on.</param> /// <param name="predicate">The predicate to check.</param> /// <returns>An optional of <typeparamref name="T"/> value.</returns> public static Optional <T> When <T>(this T source, bool predicate) => predicate?source.AsOptional() : OptionalBuilder.Empty <T>();
/// <summary> /// Converts the current instance to an optional of the specified type with value. /// </summary> /// <typeparam name="TU">The specific type of optional.</typeparam> /// <param name="value">The value to be used.</param> /// <returns>An optional that contains a value.</returns> /// <exception cref="ArgumentNullException">The <paramref name="value"/> is null.</exception> public Optional <TU> ToSome <TU>(TU value) => OptionalBuilder.Some(value);
/// <summary> /// Converts the current instance to an empty of another type. /// </summary> /// <typeparam name="TU">The type to store.</typeparam> /// <returns>An empty optional of the specific type.</returns> public Optional <TU> ToEmpty <TU>() => OptionalBuilder.Empty <TU>();