1+ // ***********************************************************************
2+ // Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+ // Author : RzR
4+ // Created On : 2025-07-11 12:38
5+ //
6+ // Last Modified By : RzR
7+ // Last Modified On : 2025-07-11 13:01
8+ // ***********************************************************************
9+ // <copyright file="FuncExtensions.cs" company="RzR SOFT & TECH">
10+ // Copyright © RzR. All rights reserved.
11+ // </copyright>
12+ //
13+ // <summary>
14+ // </summary>
15+ // ***********************************************************************
16+
17+ #region U S A G E S
18+
19+ using System ;
20+ using System . Threading . Tasks ;
21+ using DomainCommonExtensions . DataTypeExtensions ;
22+
23+ #endregion
24+
25+ namespace DomainCommonExtensions . CommonExtensions
26+ {
27+ /// <summary>
28+ /// A function extensions.
29+ /// </summary>
30+ public static class FuncExtensions
31+ {
32+ /// <summary>
33+ /// A Func<bool> extension method that query if 'func' result is true.
34+ /// </summary>
35+ /// <exception cref="ArgumentNullException">
36+ /// Thrown when one or more required arguments are null.
37+ /// </exception>
38+ /// <param name="func">The func to act on.</param>
39+ /// <returns>
40+ /// True if true, false if not.
41+ /// </returns>
42+ public static bool IsTrue ( this Func < bool > func )
43+ {
44+ if ( func . IsNull ( ) )
45+ throw new ArgumentNullException ( nameof ( func ) ) ;
46+
47+ return func . Invoke ( ) . IsTrue ( ) ;
48+ }
49+
50+ /// <summary>
51+ /// A Func<bool> extension method that query if 'func' result is false.
52+ /// </summary>
53+ /// <param name="func">The func to act on.</param>
54+ /// <returns>
55+ /// True if false, false if not.
56+ /// </returns>
57+ public static bool IsFalse ( this Func < bool > func )
58+ {
59+ return func . IsTrue ( ) . IsFalse ( ) ;
60+ }
61+
62+ /// -------------------------------------------------------------------------------------------------
63+ /// <summary>
64+ /// A Func<bool> extension method that query if 'func' result is true.
65+ /// </summary>
66+ /// <exception cref="ArgumentNullException">
67+ /// Thrown when one or more required arguments are null.
68+ /// </exception>
69+ /// <param name="func">The func to act on.</param>
70+ /// <returns>
71+ /// True if true, false if not.
72+ /// </returns>
73+ /// =================================================================================================
74+ public static bool IsTrue ( this Func < Task < bool > > func )
75+ {
76+ if ( func . IsNull ( ) )
77+ throw new ArgumentNullException ( nameof ( func ) ) ;
78+
79+ return func . Invoke ( ) . Result . IsTrue ( ) ;
80+ }
81+
82+ /// -------------------------------------------------------------------------------------------------
83+ /// <summary>
84+ /// A Func<bool> extension method that query if 'func' result is false.
85+ /// </summary>
86+ /// <param name="func">The func to act on.</param>
87+ /// <returns>
88+ /// True if false, false if not.
89+ /// </returns>
90+ /// =================================================================================================
91+ public static bool IsFalse ( this Func < Task < bool > > func )
92+ {
93+ return func . IsTrue ( ) . IsFalse ( ) ;
94+ }
95+ }
96+ }
0 commit comments