Skip to content

Commit 1d0737a

Browse files
authored
Merge pull request #42 from I-RzR-I/feature/ExtMultiple_1125
Add multiple extensions and helpers
2 parents 4712003 + 9050ad9 commit 1d0737a

File tree

23 files changed

+2146
-126
lines changed

23 files changed

+2146
-126
lines changed

docs/CHANGELOG.md

Lines changed: 126 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
### **v4.1.0.8241** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 11-11-2025
2+
* [0c9f8d8] (RzR) -> Auto commit uncommited files
3+
* [75871a1] (RzR) -> Add INI file reader helper.
4+
* [4eb45c6] (RzR) -> Add new Dictionary extension methods: `AddOrUpdate`, `AddOrUpdateValue`, `AddOrUpdateValues`, `AddOrUpdateValues`.
5+
* [3bee806] (RzR) -> Add `TaskRunnerHelper` that allow to use as `Task.Run`.
6+
* [b723c9b] (RzR) -> Add new enumerable extension method: `IsNotNullOrEmptyEnumerable`.
7+
* [8971980] (RzR) -> Add new string extension methods: `IsWebUrl`.
8+
* [fac9dce] (RzR) -> Adjust changelog version order
9+
* [c2f8fa2] (RzR) -> Add new string extension methods: `IsAllUpperCase`, `IsAllLowerCase`, `IsAllLetters`, `CleanTextToLettersNumbersAndSpace`.
10+
* [173ded1] (RzR) -> Add new string extension methods: `AddPeriod`, `RemovePeriod`, `AddPeriodValue`, `RemovePeriodValue`.
11+
* [771d45a] (RzR) -> Adjust code execution and add new tests.
12+
* [6bf5de1] (RzR) -> Add new Type extension methods: `IsNonAbstractClass`, `GetBaseTypes`, `IsInNamespaceAlternative`, `IsInExactNamespace`, `HasAttribute`.
13+
* [c92aec2] (RzR) -> Add new string extension: `NotAllowedEmpty`.
14+
* [daad073] (RzR) -> Add new enum extension: `IsDefined`.
15+
* [9126c55] (RzR) -> Add new T extension methods: `NotAllowNull`.
16+
* [a0edaf4] (RzR) -> Add new Random method: `Bool`.
17+
* [2c8da5e] (RzR) -> Add new enumerable ext: `ToHashSet`, `HasAny`.
18+
119
### **v4.0.1.8519** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 27-10-2025
220
* [2726a87] (RzR) -> Auto commit uncommited files
321
* [1282898] (RzR) -> Fix IEnumerable extension method: `Chunked`.
@@ -70,24 +88,102 @@
7088
* [17989a2] (RzR) -> Add new Enum extensions `AreEquals`.
7189
* [3e56754] (RzR) -> Add new enumerable extensions `Chunked`
7290

73-
### **v1.0.1.0823**
74-
-> Was fixed tests and was added validator for input source.<br />
75-
-> Was added `ToEnum<T>` from the string.<br />
76-
-> Was added check methods `IsTypeOfNullableInt`, `IsTypeOfFloatingPoint`, `IsTypeOfNullableFloatingPoint` from property type.
91+
### **v2.1.1.6403**
92+
-> Add new string extension: `FormatWith`;<br />
93+
-> Add new Guid/Guid? extension: `IsEmpty`;<br />
94+
-> Relocate several string extensions: `IsGuid`, `ToGuid`, `FromDoubleQuotesWithBackSlashesToGuid`;<br />
7795

78-
### **v1.0.1.1842**
79-
-> Was added new byte extension: `ToStringFromByteUnicode`, `ToHexByte`.<br />
80-
-> Was added new string extension: `ToBytesUnicode`.
96+
### **v2.1.0.0**
97+
-> Add new string extensions: `ToStringArray`, `ArrayToString`;<br />
98+
-> Add new array extensions: `AppendItem`, `AppendIfNotExists`, `RemoveItem`, `RemoveAtIdx`;<br />
99+
-> Add new enumerable extensions: `GetDuplicates`, `ForEach`, `ForEachAndReturn`;<br />
100+
-> Add passcode/password generation util;<br />
81101

82-
### **v1.0.2.1107**
83-
-> Was added new DateTime extension: `StartOfWeek`, `EndOfWeek`, `StartOfMonth`, `EndOfMonth`, `StartOfPreviousMonth`, `EndOfPreviousMonth`, `StartOfYear`, `EndOfYear`, `DaysInMonth`, `DaysInYear`, `GetIso8601WeekOfYear`.<br />
84-
-> Was added new string extension: `ReplaceExact`.<br />
85-
-> Was added new Exception extension: `GetFullError`.<br />
86-
-> Was added new ExpandoObject extension: `AddProperty`, `UpdateValue`, `GetValue`.
102+
### **v2.0.1.8588**
103+
-> Remove unused package `Microsoft.CodeAnalysis.Common`;<br />
87104

88-
### **v1.0.2.1457**
89-
-> Was added new string extension: `IfNullOrWhiteSpace`, `IfNullOrEmpty`.<br />
90-
-> Was added new TExtensions extension: `IfNotNull`.
105+
### **v2.0.0.0**
106+
-> Fix test for `CalculateAge`;<br />
107+
-> Add DateTime extension method `AsNotNull`;<br />
108+
-> Add new tests for `AsNotNull` methods;<br />
109+
-> Add `EnumerateUtils` enumerable utils some tests;<br />
110+
-> Adjust AES encryption(`AesEncryptString`, `AesDecryptString`) and expose iv as input;<br />
111+
-> Adjust dynamic property/ies select avoid `System.Linq.Dynamic.Core`;<br />
112+
113+
### **v1.3.0.0**
114+
-> Fix test for `CalculateAge`;<br />
115+
-> Add new string extensions: `IsValidJson`, `IsValidJsonObject`, `IsValidJsonArray`;<br />
116+
117+
### **v1.2.0.0**
118+
-> Add/adjust input validations in the `DataTypeExtensions` foler with extensions;<br />
119+
-> Add new string extensions: `IfNullThenEmpty`.<br />
120+
121+
### **v1.1.2.3434**
122+
-> Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.<br />
123+
124+
### **v1.1.1.7310**
125+
-> Adjust and clean up code execution.<br />
126+
-> Reorganize typeparam extensions.<br />
127+
-> Add new typeparam extensions: `IfIsNull`, `IfIsNotNull`, `IfIsNullOrFuncIsTrue`, `IfIsNullAndFuncIsTrue`, `IfFuncIsTrue`, `IfFuncIsFalse`, `IfFunc`, `IfNull`, `IfNotNull`.<br />
128+
129+
### **v1.1.0.0**
130+
-> Remove unused packages.<br />
131+
-> Downgrade some package versions to cover target frameworks.<br />
132+
-> Fix some warnings and disposable objects.<br />
133+
-> Fix tests.
134+
135+
### **v1.0.14.6517**
136+
-> Fix some enums extensions.<br />
137+
-> Add new methods (`AppendTo`, `GetPropertiesInfoFromSource`) in `TExtensions`.
138+
139+
### **v1.0.13.8399**
140+
-> Add excel column name generator `GetExcelColumnName`.<br />
141+
-> Adjust method modifier for `GetDuplicates`.<br />
142+
143+
### **v1.0.12.1447**
144+
-> Add IDataReader extensions to convert object in specific type.<br />
145+
146+
### **v1.0.11.1319**
147+
-> Fix wrong modification.<br />
148+
149+
### **v1.0.10.2315**
150+
-> Update lib version. Add option to sign the new version of the files.<br />
151+
-> Small code refactor.
152+
153+
### **v1.0.9.2108**
154+
-> Added object extensions `ThrowIfArgNull`, `ThrowArgIfNull`.<br />
155+
-> Added bool extensions `IsTrue`, `IsFalse`.<br />
156+
-> Added null check extensions `IsNotNull`, `IsDbNull`.<br />
157+
-> Added string extensions `ThrowArgIfNull`, `ThrowArgIfNullOrEmpty`, `ThrowIfArgNull`, `ThrowIfArgNullOrEmpty`.<br />
158+
-> Adjust validation for input params at some methods.
159+
-> Small code refactor.
160+
161+
### **v1.0.8.0638**
162+
-> Added string extension `GetHashSha512String`, `FromSpaceSeparatedString`, `IsMissing`, `IsNullOrEmpty`, `AddQueryString`, `AddHashFragment`, `GetOrigin`, `Obfuscate`.<br />
163+
-> Added Enumerable extension `ToSpaceSeparatedString`, `HasDuplicates`, `GetDuplicates`.<br />
164+
165+
### **v1.0.7.0535**
166+
-> Add in directory helper new methods: `FileCount` x3, `DirectoryFileCount`.<br />
167+
168+
### **v1.0.6.1341**
169+
-> Update vulnerable library version.<br />
170+
171+
### **v1.0.5.2131**
172+
-> Added string extension `ParseToInt`, `ParseNullableInt`, `TryParseInt`.<br />
173+
-> Added list extension `ActionForEach`.<br />
174+
175+
### **v1.0.5.1849**
176+
-> Added string extension `Contains`.<br />
177+
-> Added int/long extension `IsLessZero`.<br />
178+
-> Was added new Type extension: `GetStringPropertyNames`, `GetStringPropertyInfos`, `GetPropertyInfos`.<br />
179+
180+
### **v1.0.4.1925**
181+
-> Added support for net framework.<br />
182+
183+
### **v1.0.3.1101**
184+
-> Was added new object extension: `SerializeToString` .<br />
185+
-> Was added new string extension: `DeserializeToObject` .<br />
186+
-> Was added new T extension: `SerializeToXmlDoc` .<br />
91187

92188
### **v1.0.3.0**
93189
-> Was renamed `Utils` to `GeneralUtils`.<br />
@@ -114,99 +210,21 @@
114210
-> Was added new `EnumerableExtensions` with methods: `Replace`, `Join`, `IsLast`, `IsFirst`, `GetDifferences`, `ContainsAny`, `AnyStartWith` (input: IEnumerable<string>, string), `ToObservableCollection`, `Randomize`, `Transpose`, `ToCollection`, `Combinations`, `ToDataTable`, `ToDataTableDynamic`, `IsNullOrEmptyEnumerable`, `WithIndex`, `ListToString`, `CloneCollection`, `NotNull`.<br />
115211
-> Was added new `ArrayExtensions` with methods: `IndexOf`.<br />
116212

117-
### **v1.0.3.1101**
118-
-> Was added new object extension: `SerializeToString` .<br />
119-
-> Was added new string extension: `DeserializeToObject` .<br />
120-
-> Was added new T extension: `SerializeToXmlDoc` .<br />
121-
122-
### **v1.0.4.1925**
123-
-> Added support for net framework.<br />
124-
125-
### **v1.0.5.1849**
126-
-> Added string extension `Contains`.<br />
127-
-> Added int/long extension `IsLessZero`.<br />
128-
-> Was added new Type extension: `GetStringPropertyNames`, `GetStringPropertyInfos`, `GetPropertyInfos`.<br />
129-
130-
### **v1.0.5.2131**
131-
-> Added string extension `ParseToInt`, `ParseNullableInt`, `TryParseInt`.<br />
132-
-> Added list extension `ActionForEach`.<br />
133-
134-
### **v1.0.6.1341**
135-
-> Update vulnerable library version.<br />
136-
137-
### **v1.0.7.0535**
138-
-> Add in directory helper new methods: `FileCount` x3, `DirectoryFileCount`.<br />
139-
140-
### **v1.0.8.0638**
141-
-> Added string extension `GetHashSha512String`, `FromSpaceSeparatedString`, `IsMissing`, `IsNullOrEmpty`, `AddQueryString`, `AddHashFragment`, `GetOrigin`, `Obfuscate`.<br />
142-
-> Added Enumerable extension `ToSpaceSeparatedString`, `HasDuplicates`, `GetDuplicates`.<br />
143-
144-
### **v1.0.9.2108**
145-
-> Added object extensions `ThrowIfArgNull`, `ThrowArgIfNull`.<br />
146-
-> Added bool extensions `IsTrue`, `IsFalse`.<br />
147-
-> Added null check extensions `IsNotNull`, `IsDbNull`.<br />
148-
-> Added string extensions `ThrowArgIfNull`, `ThrowArgIfNullOrEmpty`, `ThrowIfArgNull`, `ThrowIfArgNullOrEmpty`.<br />
149-
-> Adjust validation for input params at some methods.
150-
-> Small code refactor.
151-
152-
### **v1.0.10.2315**
153-
-> Update lib version. Add option to sign the new version of the files.<br />
154-
-> Small code refactor.
155-
156-
### **v1.0.11.1319**
157-
-> Fix wrong modification.<br />
158-
159-
### **v1.0.12.1447**
160-
-> Add IDataReader extensions to convert object in specific type.<br />
161-
162-
### **v1.0.13.8399**
163-
-> Add excel column name generator `GetExcelColumnName`.<br />
164-
-> Adjust method modifier for `GetDuplicates`.<br />
165-
-> Fix tests.
166-
167-
### **v1.0.14.6517**
168-
-> Fix some enums extensions.<br />
169-
-> Add new methods (`AppendTo`, `GetPropertiesInfoFromSource`) in `TExtensions`.
170-
171-
### **v1.1.0.0**
172-
-> Remove unused packages.<br />
173-
-> Downgrade some package versions to cover target frameworks.<br />
174-
-> Fix some warnings and disposable objects.<br />
175-
176-
### **v1.1.1.7310**
177-
-> Adjust and clean up code execution.<br />
178-
-> Reorganize typeparam extensions.<br />
179-
-> Add new typeparam extensions: `IfIsNull`, `IfIsNotNull`, `IfIsNullOrFuncIsTrue`, `IfIsNullAndFuncIsTrue`, `IfFuncIsTrue`, `IfFuncIsFalse`, `IfFunc`, `IfNull`, `IfNotNull`.<br />
180-
181-
### **v1.1.2.3434**
182-
-> Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.<br />
183-
184-
### **v1.2.0.0**
185-
-> Add/adjust input validations in the `DataTypeExtensions` foler with extensions;<br />
186-
-> Add new string extensions: `IfNullThenEmpty`.<br />
187-
188-
### **v1.3.0.0**
189-
-> Fix test for `CalculateAge`;<br />
190-
-> Add new string extensions: `IsValidJson`, `IsValidJsonObject`, `IsValidJsonArray`;<br />
191-
192-
### **v2.0.0.0**
193-
-> Fix test for `CalculateAge`;<br />
194-
-> Add DateTime extension method `AsNotNull`;<br />
195-
-> Add new tests for `AsNotNull` methods;<br />
196-
-> Add `EnumerateUtils` enumerable utils some tests;<br />
197-
-> Adjust AES encryption(`AesEncryptString`, `AesDecryptString`) and expose iv as input;<br />
198-
-> Adjust dynamic property/ies select avoid `System.Linq.Dynamic.Core`;<br />
213+
### **v1.0.2.1457**
214+
-> Was added new string extension: `IfNullOrWhiteSpace`, `IfNullOrEmpty`.<br />
215+
-> Was added new TExtensions extension: `IfNotNull`.
199216

200-
### **v2.0.1.8588**
201-
-> Remove unused package `Microsoft.CodeAnalysis.Common`;<br />
217+
### **v1.0.2.1107**
218+
-> Was added new DateTime extension: `StartOfWeek`, `EndOfWeek`, `StartOfMonth`, `EndOfMonth`, `StartOfPreviousMonth`, `EndOfPreviousMonth`, `StartOfYear`, `EndOfYear`, `DaysInMonth`, `DaysInYear`, `GetIso8601WeekOfYear`.<br />
219+
-> Was added new string extension: `ReplaceExact`.<br />
220+
-> Was added new Exception extension: `GetFullError`.<br />
221+
-> Was added new ExpandoObject extension: `AddProperty`, `UpdateValue`, `GetValue`.
202222

203-
### **v2.1.0.0**
204-
-> Add new string extensions: `ToStringArray`, `ArrayToString`;<br />
205-
-> Add new array extensions: `AppendItem`, `AppendIfNotExists`, `RemoveItem`, `RemoveAtIdx`;<br />
206-
-> Add new enumerable extensions: `GetDuplicates`, `ForEach`, `ForEachAndReturn`;<br />
207-
-> Add passcode/password generation util;<br />
223+
### **v1.0.1.1842**
224+
-> Was added new byte extension: `ToStringFromByteUnicode`, `ToHexByte`.<br />
225+
-> Was added new string extension: `ToBytesUnicode`.
208226

209-
### **v2.1.1.6403**
210-
-> Add new string extension: `FormatWith`;<br />
211-
-> Add new Guid/Guid? extension: `IsEmpty`;<br />
212-
-> Relocate several string extensions: `IsGuid`, `ToGuid`, `FromDoubleQuotesWithBackSlashesToGuid`;<br />
227+
### **v1.0.1.0823**
228+
-> Was fixed tests and was added validator for input source.<br />
229+
-> Was added `ToEnum<T>` from the string.<br />
230+
-> Was added check methods `IsTypeOfNullableInt`, `IsTypeOfFloatingPoint`, `IsTypeOfNullableFloatingPoint` from property type.

src/DomainCommonExtensions/ArraysExtensions/DictionaryExtensions.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,67 @@ public static bool ContainsAnyKeys<TKey, TValue>(this IDictionary<TKey, TValue>
277277
{
278278
return source.IsNotNull() && keys.NotNull().Any(source.ContainsKey);
279279
}
280+
281+
/// <summary>
282+
/// An IDictionary&lt;TKey,TValue&gt; extension method that adds an or update value.
283+
/// </summary>
284+
/// <typeparam name="TKey">Type of the key.</typeparam>
285+
/// <typeparam name="TValue">Type of the value.</typeparam>
286+
/// <param name="source">The source to act on.</param>
287+
/// <param name="key">Required. Search key.</param>
288+
/// <param name="value">Required. Value.</param>
289+
public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TValue value)
290+
{
291+
source[key] = value;
292+
}
293+
294+
/// -------------------------------------------------------------------------------------------------
295+
/// <summary>
296+
/// An IDictionary&lt;TKey,TValue[]&gt; extension method that adds an or update value.
297+
/// </summary>
298+
/// <typeparam name="TKey">Type of the key.</typeparam>
299+
/// <typeparam name="TValue">Type of the value.</typeparam>
300+
/// <param name="source">The source to act on.</param>
301+
/// <param name="key">Required. Search key.</param>
302+
/// <param name="value">.</param>
303+
/// =================================================================================================
304+
public static void AddOrUpdateValue<TKey, TValue>(this IDictionary<TKey, TValue[]> source, TKey key, TValue value)
305+
{
306+
source[key] = new TValue[1] { value };
307+
}
308+
309+
/// <summary>
310+
/// An IDictionary&lt;TKey,TValue[]&gt; extension method that adds an or update values.
311+
/// </summary>
312+
/// <typeparam name="TKey">Type of the key.</typeparam>
313+
/// <typeparam name="TValue">Type of the value.</typeparam>
314+
/// <param name="source">The source to act on.</param>
315+
/// <param name="key">Required. Search key.</param>
316+
/// <param name="value">Required. Value.</param>
317+
public static void AddOrUpdateValues<TKey, TValue>(this IDictionary<TKey, TValue[]> source, TKey key, TValue value)
318+
{
319+
if (source.TryGetValue(key, out var currentValues).IsTrue())
320+
source[key] = currentValues.NotNull().AppendItem(value);
321+
else
322+
source[key] = new TValue[1] { value };
323+
}
324+
325+
/// -------------------------------------------------------------------------------------------------
326+
/// <summary>
327+
/// An IDictionary&lt;TKey,TValue[]&gt; extension method that adds an or update values.
328+
/// </summary>
329+
/// <typeparam name="TKey">Type of the key.</typeparam>
330+
/// <typeparam name="TValue">Type of the value.</typeparam>
331+
/// <param name="source">The source to act on.</param>
332+
/// <param name="key">Required. Search key.</param>
333+
/// <param name="values">A variable-length parameters list containing values.</param>
334+
/// =================================================================================================
335+
public static void AddOrUpdateValues<TKey, TValue>(this IDictionary<TKey, TValue[]> source, TKey key, params TValue[] values)
336+
{
337+
if (source.TryGetValue(key, out var currentValues).IsTrue())
338+
source[key] = currentValues.NotNull().AppendItem(values);
339+
else
340+
source[key] = values;
341+
}
280342
}
281343
}

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ public static bool IsNullOrEmptyEnumerable<T>(this IEnumerable<T> source)
341341
return source.IsNull() || !source.Any();
342342
}
343343

344+
/// <summary>
345+
/// An IEnumerable&lt;T&gt; extension method that query if 'enumerable' is not null or empty
346+
/// enumerable.
347+
/// </summary>
348+
/// <typeparam name="T">Generic type parameter.</typeparam>
349+
/// <param name="enumerable">.</param>
350+
/// <returns>
351+
/// True if not null or empty enumerable, false if not.
352+
/// </returns>
353+
public static bool IsNotNullOrEmptyEnumerable<T>(this IEnumerable<T> enumerable)
354+
{
355+
return !enumerable.IsNullOrEmptyEnumerable();
356+
}
357+
344358
#if NET45_OR_GREATER || NET || NETSTANDARD1_0_OR_GREATER
345359
/// <summary>
346360
/// Format list to list with item index
@@ -799,5 +813,48 @@ public static string ConvertToQuerystring(this IEnumerable collection, string la
799813

800814
return result;
801815
}
816+
817+
/// <summary>
818+
/// An IEnumerable&lt;T&gt; extension method that converts a source to a hash set.
819+
/// </summary>
820+
/// <typeparam name="T">Generic type parameter.</typeparam>
821+
/// <param name="source">The source for this extension method.</param>
822+
/// <returns>
823+
/// Source as an ISet&lt;T&gt;
824+
/// </returns>
825+
public static ISet<T> ToHashSet<T>(this IEnumerable<T> source)
826+
{
827+
if (source is ISet<T> set)
828+
{
829+
return set;
830+
}
831+
832+
return new HashSet<T>(source);
833+
}
834+
835+
/// <summary>
836+
/// An IEnumerable&lt;TSource&gt; extension method that query if 'source' has any.
837+
/// </summary>
838+
/// <typeparam name="TSource">Type of the source.</typeparam>
839+
/// <param name="source">.</param>
840+
/// <param name="predicate">The predicate.</param>
841+
/// <returns>
842+
/// True if any, false if not.
843+
/// </returns>
844+
public static bool HasAny<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
845+
{
846+
DomainEnsure.IsNotNull(source, nameof(source));
847+
DomainEnsure.IsNotNull(predicate, nameof(predicate));
848+
849+
foreach (TSource item in source)
850+
{
851+
if (predicate(item))
852+
{
853+
return true;
854+
}
855+
}
856+
857+
return false;
858+
}
802859
}
803860
}

0 commit comments

Comments
 (0)