Skip to content

Commit 79d9ff6

Browse files
authored
Merge pull request #34 from I-RzR-I/feature/FuncStringNumExtensions
Feature/func string num extensions
2 parents ce7993b + 3e9e911 commit 79d9ff6

12 files changed

Lines changed: 669 additions & 37 deletions

File tree

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### **v2.3.0.7698** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 15-07-2025
2+
* [f300bd2] (RzR) -> Auto commit uncommited files
3+
* [067dd42] (RzR) -> Add alternative extension method for `WithIndex`
4+
* [4839a72] (RzR) -> Add string extension methods `IfStartsWith` and `IfNotStartsWith`.
5+
* [572b664] (RzR) -> Add string extension methods `IfContains` and `IfNotContains`
6+
* [872a4f6] (RzR) -> Add generic equality compare object `IfEquals` and `IfNotEquals`
7+
* [50c5dcc] (RzR) -> Add func extensions sync/async `IsTrue`, `IsFalse`.
8+
19
### v**2.2.0.8487** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 27-06-2025
210
* [9b9d498] (RzR) -> Auto commit uncommited files
311
* [e72cb92] (RzR) -> Adjust path to test projects in scripts

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using DomainCommonExtensions.CommonExtensions;
1818
using DomainCommonExtensions.CommonExtensions.TypeParam;
1919
using DomainCommonExtensions.DataTypeExtensions;
20+
using DomainCommonExtensions.Models;
2021
using System;
2122
using System.Collections.Generic;
2223
using System.Collections.ObjectModel;
@@ -344,6 +345,23 @@ public static bool IsNullOrEmptyEnumerable<T>(this IEnumerable<T> source)
344345
}
345346
#endif
346347

348+
/// <summary>
349+
/// Format list to list with item index
350+
/// </summary>
351+
/// <param name="self">Input list</param>
352+
/// <returns></returns>
353+
/// <typeparam name="T">List type</typeparam>
354+
/// <remarks></remarks>
355+
public static IEnumerable<WithIndexModel<T>> WithIndexModel<T>(this IEnumerable<T> self)
356+
{
357+
return self?.Select(
358+
(item, index) => new WithIndexModel<T>()
359+
{
360+
Index = index,
361+
Item = item
362+
}) ?? new List<WithIndexModel<T>>();
363+
}
364+
347365
/// <summary>
348366
/// Generates a string from a list of values with the given delimiter
349367
/// </summary>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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&lt;bool&gt; 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&lt;bool&gt; 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&lt;bool&gt; 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&lt;bool&gt; 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+
}

src/DomainCommonExtensions/CommonExtensions/TypeParam/TypeParamExtensions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,41 @@ public static T[] SubArray<T>(this T[] array, int offset, int length)
182182
.Take(length)
183183
.ToArray();
184184
}
185+
186+
/// <summary>
187+
/// A T extension method that check if source and search value are equals.
188+
/// </summary>
189+
/// <typeparam name="T">Generic type parameter.</typeparam>
190+
/// <param name="source">Source object value.</param>
191+
/// <param name="searchValue">The search value.</param>
192+
/// <param name="resultValue">Result object value.</param>
193+
/// <returns>
194+
/// A T. If objects are equals then return defaultValue.
195+
/// </returns>
196+
public static T IfEquals<T>(this T source, T searchValue, T resultValue)
197+
{
198+
if (source.IsNull() || searchValue.IsNull())
199+
return resultValue;
200+
201+
return EqualityComparer<T>.Default.Equals(source, searchValue) ? resultValue : source;
202+
}
203+
204+
/// <summary>
205+
/// A T extension method that check if source and search value are not equals.
206+
/// </summary>
207+
/// <typeparam name="T">Generic type parameter.</typeparam>
208+
/// <param name="source">Source object value.</param>
209+
/// <param name="searchValue">The search value.</param>
210+
/// <param name="resultValue">Result object value.</param>
211+
/// <returns>
212+
/// A T. If objects are not equals then return resultValue.
213+
/// </returns>
214+
public static T IfNotEquals<T>(this T source, T searchValue, T resultValue)
215+
{
216+
if (source.IsNull() || searchValue.IsNull())
217+
return resultValue;
218+
219+
return EqualityComparer<T>.Default.Equals(source, searchValue).IsFalse() ? resultValue : source;
220+
}
185221
}
186222
}

src/DomainCommonExtensions/DataTypeExtensions/StringExtensions.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,5 +1682,61 @@ public static string FormatWith(this string source, params object[] args)
16821682

16831683
return string.Format(CultureInfo.CurrentCulture, source, args);
16841684
}
1685+
1686+
/// <summary>
1687+
/// A string extension method that check if source contains.
1688+
/// </summary>
1689+
/// <param name="source">The input.</param>
1690+
/// <param name="searchValue">The search value.</param>
1691+
/// <param name="resultValue">Default value to return.</param>
1692+
/// <returns>
1693+
/// A string.
1694+
/// </returns>
1695+
public static string IfContains(this string source, string searchValue, string resultValue)
1696+
{
1697+
return source.Contains(searchValue).IsTrue() ? resultValue : source;
1698+
}
1699+
1700+
/// <summary>
1701+
/// A string extension method that check if source not contains.
1702+
/// </summary>
1703+
/// <param name="source">The input.</param>
1704+
/// <param name="searchValue">The search value.</param>
1705+
/// <param name="resultValue">Default value to return.</param>
1706+
/// <returns>
1707+
/// A string.
1708+
/// </returns>
1709+
public static string IfNotContains(this string source, string searchValue, string resultValue)
1710+
{
1711+
return source.Contains(searchValue).IsFalse() ? resultValue : source;
1712+
}
1713+
1714+
/// <summary>
1715+
/// A string extension method that check if source starts with.
1716+
/// </summary>
1717+
/// <param name="source">The input.</param>
1718+
/// <param name="searchValue">The search value.</param>
1719+
/// <param name="resultValue">Default value to return.</param>
1720+
/// <returns>
1721+
/// A string.
1722+
/// </returns>
1723+
public static string IfStartsWith(this string source, string searchValue, string resultValue)
1724+
{
1725+
return source.StartsWith(searchValue).IsTrue() ? resultValue : source;
1726+
}
1727+
1728+
/// <summary>
1729+
/// A string extension method that check if source not starts with.
1730+
/// </summary>
1731+
/// <param name="source">The input.</param>
1732+
/// <param name="searchValue">The search value.</param>
1733+
/// <param name="resultValue">Default value to return.</param>
1734+
/// <returns>
1735+
/// A string.
1736+
/// </returns>
1737+
public static string IfNotStartsWith(this string source, string searchValue, string resultValue)
1738+
{
1739+
return source.StartsWith(searchValue).IsFalse() ? resultValue : source;
1740+
}
16851741
}
16861742
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+
// Author : RzR
4+
// Created On : 2025-07-15 18:33
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2025-07-15 18:33
8+
// ***********************************************************************
9+
// <copyright file="WithIndexModel.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
namespace DomainCommonExtensions.Models
18+
{
19+
/// -------------------------------------------------------------------------------------------------
20+
/// <summary>
21+
/// A data Model for the with index enumerable extension method.
22+
/// </summary>
23+
/// <typeparam name="T">Generic type parameter.</typeparam>
24+
/// =================================================================================================
25+
public struct WithIndexModel<T>
26+
{
27+
/// -------------------------------------------------------------------------------------------------
28+
/// <summary>
29+
/// Gets or sets the zero-based index of this object.
30+
/// </summary>
31+
/// <value>
32+
/// The index.
33+
/// </value>
34+
/// =================================================================================================
35+
public int Index { get; set; }
36+
37+
/// -------------------------------------------------------------------------------------------------
38+
/// <summary>
39+
/// Gets or sets the item.
40+
/// </summary>
41+
/// <value>
42+
/// The item.
43+
/// </value>
44+
/// =================================================================================================
45+
public T Item { get; set; }
46+
}
47+
}

src/shared/GeneralAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
4848
#endif
4949

50-
[assembly: AssemblyVersion("2.2.0.8487")]
51-
[assembly: AssemblyFileVersion("2.2.0.8487")]
52-
[assembly: AssemblyInformationalVersion("2.2.0.8487")]
50+
[assembly: AssemblyVersion("2.3.0.7698")]
51+
[assembly: AssemblyFileVersion("2.3.0.7698")]
52+
[assembly: AssemblyInformationalVersion("2.3.0.7698")]

0 commit comments

Comments
 (0)