Skip to content

Commit ce7993b

Browse files
authored
Merge pull request #33 from I-RzR-I/feature/NewMethodsImprovs
Feature/new methods improvs
2 parents c3b9d72 + 15c05e9 commit ce7993b

File tree

17 files changed

+1182
-262
lines changed

17 files changed

+1182
-262
lines changed

build/generateNextMajorVersion.bat

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@echo off
2+
cls
3+
4+
echo Write the source branch name (you current branch name, where were the changes made):
5+
set /p userDefinedSourceBranch=
6+
echo.
7+
echo Write the destination branch name (the branch from which you can get the latest changes, like 'develop' or 'main/master'):
8+
set /p userDefinedDestinationBranch=
9+
echo.
10+
11+
:: Set init params value
12+
set applicationName=DomainCommonExtensions
13+
set runVersionIncrement=y
14+
set runGenChangeLog=y
15+
:: If runBuild > y(yes), build in release mode
16+
set runBuild=y
17+
set runSolutionTest=y
18+
set runTest=y
19+
set runPack=y
20+
set assemblyPath=$('..\src\shared\GeneralAssemblyInfo.cs')
21+
set genType=0
22+
set setInChangeLogNewVersion=y
23+
set autoCommitAndPush=n
24+
set autoGetLatestDevelop=y
25+
set changeLogPath=$('..\docs\CHANGELOG.MD')
26+
set sourceBranch=%userDefinedSourceBranch%
27+
set destinationBranch=%userDefinedDestinationBranch%
28+
set customVersion=$null
29+
set solutionPath=$('..\src\RzR.Shared.Extensions.sln')
30+
set packResultPath=$('..\nuget\')
31+
set packProjectsPath=$('..\src\DomainCommonExtensions\DomainCommonExtensions.csproj')
32+
set testProjectsPath=$('..\src\tests\DataTypeTests\DataTypeTests.csproj')
33+
34+
35+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36+
echo ::: Initialize: :::
37+
echo ::: - New application version generation :::
38+
echo ::: - Change log generation :::
39+
echo ::: - Build :::
40+
echo ::: - Test :::
41+
echo ::: - Create package :::
42+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43+
echo:
44+
echo:
45+
46+
PowerShell -NoProfile -ExecutionPolicy ByPass -Command ".\GenerateBuildInfo.exe -scriptCommands \"runVersionIncrement=%runVersionIncrement%;runGenChangeLog=%runGenChangeLog%;runBuild=%runBuild%;runSolutionTest=%runSolutionTest%;runTest=%runTest%;runPack=%runPack%;setInChangeLogNewVersion=%setInChangeLogNewVersion%;autoCommitAndPush=%autoCommitAndPush%;autoGetLatestDevelop=%autoGetLatestDevelop%;changeLogPath=%changeLogPath%;sourceBranch=%sourceBranch%;destinationBranch=%destinationBranch%;assemblyPath=%assemblyPath%;customVersion=%customVersion%;genType=%genType%;solutionPath=%solutionPath%;packResultPath=%packResultPath%;packProjectsPath=%packProjectsPath%;testProjectsPath=%testProjectsPath%\"";
47+
48+
echo
49+
pause

build/generateNextMinorVersion.bat

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@echo off
2+
cls
3+
4+
echo Write the source branch name (you current branch name, where were the changes made):
5+
set /p userDefinedSourceBranch=
6+
echo.
7+
echo Write the destination branch name (the branch from which you can get the latest changes, like 'develop' or 'main/master'):
8+
set /p userDefinedDestinationBranch=
9+
echo.
10+
11+
:: Set init params value
12+
set applicationName=DomainCommonExtensions
13+
set runVersionIncrement=y
14+
set runGenChangeLog=y
15+
:: If runBuild > y(yes), build in release mode
16+
set runBuild=y
17+
set runSolutionTest=y
18+
set runTest=y
19+
set runPack=y
20+
set assemblyPath=$('..\src\shared\GeneralAssemblyInfo.cs')
21+
set genType=1
22+
set setInChangeLogNewVersion=y
23+
set autoCommitAndPush=n
24+
set autoGetLatestDevelop=y
25+
set changeLogPath=$('..\docs\CHANGELOG.MD')
26+
set sourceBranch=%userDefinedSourceBranch%
27+
set destinationBranch=%userDefinedDestinationBranch%
28+
set customVersion=$null
29+
set solutionPath=$('..\src\RzR.Shared.Extensions.sln')
30+
set packResultPath=$('..\nuget\')
31+
set packProjectsPath=$('..\src\DomainCommonExtensions\DomainCommonExtensions.csproj')
32+
set testProjectsPath=$('..\src\tests\DataTypeTests\DataTypeTests.csproj')
33+
34+
35+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36+
echo ::: Initialize: :::
37+
echo ::: - New application version generation :::
38+
echo ::: - Change log generation :::
39+
echo ::: - Build :::
40+
echo ::: - Test :::
41+
echo ::: - Create package :::
42+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43+
echo:
44+
echo:
45+
46+
PowerShell -NoProfile -ExecutionPolicy ByPass -Command ".\GenerateBuildInfo.exe -scriptCommands \"runVersionIncrement=%runVersionIncrement%;runGenChangeLog=%runGenChangeLog%;runBuild=%runBuild%;runSolutionTest=%runSolutionTest%;runTest=%runTest%;runPack=%runPack%;setInChangeLogNewVersion=%setInChangeLogNewVersion%;autoCommitAndPush=%autoCommitAndPush%;autoGetLatestDevelop=%autoGetLatestDevelop%;changeLogPath=%changeLogPath%;sourceBranch=%sourceBranch%;destinationBranch=%destinationBranch%;assemblyPath=%assemblyPath%;customVersion=%customVersion%;genType=%genType%;solutionPath=%solutionPath%;packResultPath=%packResultPath%;packProjectsPath=%packProjectsPath%;testProjectsPath=%testProjectsPath%\"";
47+
48+
echo
49+
pause

build/generateNextPatchVersion.bat

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@echo off
2+
cls
3+
4+
echo Write the source branch name (you current branch name, where were the changes made):
5+
set /p userDefinedSourceBranch=
6+
echo.
7+
echo Write the destination branch name (the branch from which you can get the latest changes, like 'develop' or 'main/master'):
8+
set /p userDefinedDestinationBranch=
9+
echo.
10+
11+
:: Set init params value
12+
set applicationName=DomainCommonExtensions
13+
set runVersionIncrement=y
14+
set runGenChangeLog=y
15+
:: If runBuild > y(yes), build in release mode
16+
set runBuild=y
17+
set runSolutionTest=y
18+
set runTest=y
19+
set runPack=y
20+
set assemblyPath=$('..\src\shared\GeneralAssemblyInfo.cs')
21+
set genType=2
22+
set setInChangeLogNewVersion=y
23+
set autoCommitAndPush=n
24+
set autoGetLatestDevelop=y
25+
set changeLogPath=$('..\docs\CHANGELOG.MD')
26+
set sourceBranch=%userDefinedSourceBranch%
27+
set destinationBranch=%userDefinedDestinationBranch%
28+
set customVersion=$null
29+
set solutionPath=$('..\src\RzR.Shared.Extensions.sln')
30+
set packResultPath=$('..\nuget\')
31+
set packProjectsPath=$('..\src\DomainCommonExtensions\DomainCommonExtensions.csproj')
32+
set testProjectsPath=$('..\src\tests\DataTypeTests\DataTypeTests.csproj')
33+
34+
35+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36+
echo ::: Initialize: :::
37+
echo ::: - New application version generation :::
38+
echo ::: - Change log generation :::
39+
echo ::: - Build :::
40+
echo ::: - Test :::
41+
echo ::: - Create package :::
42+
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43+
echo:
44+
echo:
45+
46+
PowerShell -NoProfile -ExecutionPolicy ByPass -Command ".\GenerateBuildInfo.exe -scriptCommands \"runVersionIncrement=%runVersionIncrement%;runGenChangeLog=%runGenChangeLog%;runBuild=%runBuild%;runSolutionTest=%runSolutionTest%;runTest=%runTest%;runPack=%runPack%;setInChangeLogNewVersion=%setInChangeLogNewVersion%;autoCommitAndPush=%autoCommitAndPush%;autoGetLatestDevelop=%autoGetLatestDevelop%;changeLogPath=%changeLogPath%;sourceBranch=%sourceBranch%;destinationBranch=%destinationBranch%;assemblyPath=%assemblyPath%;customVersion=%customVersion%;genType=%genType%;solutionPath=%solutionPath%;packResultPath=%packResultPath%;packProjectsPath=%packProjectsPath%;testProjectsPath=%testProjectsPath%\"";
47+
48+
echo
49+
pause

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### v**2.2.0.8487** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 27-06-2025
2+
* [9b9d498] (RzR) -> Auto commit uncommited files
3+
* [e72cb92] (RzR) -> Adjust path to test projects in scripts
4+
* [141087f] (RzR) -> Add changelog and version scripts
5+
* [11e19df] (RzR) -> Add DataTable extensions `ToJson` and refactor anonimous class factory
6+
* [17989a2] (RzR) -> Add new Enum extensions `AreEquals`.
7+
* [3e56754] (RzR) -> Add new enumerable extensions `Chunked`
8+
19
### **v1.0.1.0823**
210
-> Was fixed tests and was added validator for input source.<br />
311
-> Was added `ToEnum<T>` from the string.<br />

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
// </summary>
1515
// ***********************************************************************
1616

17+
using DomainCommonExtensions.CommonExtensions;
18+
using DomainCommonExtensions.CommonExtensions.TypeParam;
19+
using DomainCommonExtensions.DataTypeExtensions;
1720
using System;
1821
using System.Collections.Generic;
1922
using System.Collections.ObjectModel;
2023
using System.ComponentModel;
24+
using System.Data;
2125
using System.Diagnostics.Contracts;
2226
using System.Linq;
2327
using System.Text;
24-
using DomainCommonExtensions.CommonExtensions;
25-
using System.Data;
26-
using DomainCommonExtensions.CommonExtensions.TypeParam;
27-
using DomainCommonExtensions.DataTypeExtensions;
2828

2929
// ReSharper disable UnusedParameter.Local
3030
// ReSharper restore PossibleMultipleEnumeration
@@ -519,5 +519,38 @@ public static IEnumerable<T> ForEachAndReturn<T>(this IEnumerable<T> list, Actio
519519

520520
return list;
521521
}
522+
523+
/// <summary>
524+
/// Chunk source array of data by size.
525+
/// </summary>
526+
/// <param name="source">Source list/array.</param>
527+
/// <param name="chunkSize">The chunk size. Default value is 100.</param>
528+
/// <typeparam name="T">Type of list</typeparam>
529+
/// <returns></returns>
530+
/// <remarks></remarks>
531+
public static IEnumerable<IEnumerable<T>> Chunked<T>(this IEnumerable<T> source, int chunkSize = 100)
532+
{
533+
if (source.IsNullOrEmptyEnumerable())
534+
return new List<IEnumerable<T>>();
535+
if (chunkSize.IsNull() || chunkSize.IsLessOrEqualZero())
536+
return new List<IEnumerable<T>>(1) { source };
537+
538+
var chunkArray = source.ToArray();
539+
var chunksCount = (int)Math.Ceiling((double)source.Count() / chunkSize);
540+
var chunks = new List<IEnumerable<T>>(chunksCount);
541+
542+
for (var chunkIndex = 0; chunkIndex < chunksCount; chunkIndex++)
543+
{
544+
var newChunkSize = chunkIndex == chunksCount - 1 ? chunkArray.Length - (chunkSize * chunkIndex) : chunkSize;
545+
var newChunkSourceIndex = chunkIndex.IsZero() ? chunkIndex : (chunkSize * chunkIndex) - 1;
546+
547+
var chunk = new T[newChunkSize];
548+
Array.Copy(chunkArray, newChunkSourceIndex, chunk, 0, newChunkSize);
549+
550+
chunks.Add(chunk);
551+
}
552+
553+
return chunks;
554+
}
522555
}
523556
}

src/DomainCommonExtensions/CommonExtensions/SystemData/DataTableExtensions.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616

1717
#region U S A G E S
1818

19+
#if NET || NETSTANDARD2_0_OR_GREATER
20+
using DomainCommonExtensions.Helpers;
21+
using DomainCommonExtensions.Helpers.Internal.AnonymousSelect.Factory;
22+
#endif
23+
1924
using System;
2025
using System.Collections.Generic;
2126
using System.Data;
2227
using System.Linq;
2328

29+
// ReSharper disable RedundantArgumentDefaultValue
30+
2431
#endregion
2532

2633
namespace DomainCommonExtensions.CommonExtensions.SystemData
@@ -65,5 +72,84 @@ public static class DataTableExtensions
6572

6673
return list;
6774
}
75+
76+
/// <summary>
77+
/// System.Data.DataTable to generic list T.
78+
/// </summary>
79+
/// <param name="table">.</param>
80+
/// <param name="type">The type.</param>
81+
/// <param name="excludeProp">(Optional) The exclude property.</param>
82+
/// <returns>
83+
/// The given data converted to a List&lt;dynamic&gt;
84+
/// </returns>
85+
public static List<dynamic> ToList(this DataTable table, Type type, string excludeProp = "Item")
86+
{
87+
var list = new List<dynamic>();
88+
var typeProperties = type.GetProperties().Where(x => x.Name != excludeProp)
89+
.Select(propertyInfo => new
90+
{
91+
PropertyInfo = propertyInfo,
92+
Type = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType
93+
}).ToList();
94+
95+
foreach (var row in table.Rows.Cast<DataRow>())
96+
{
97+
var obj = Activator.CreateInstance(type);
98+
foreach (var typeProperty in typeProperties)
99+
{
100+
var value = row[typeProperty.PropertyInfo.Name];
101+
var safeValue = value == null || DBNull.Value.Equals(value)
102+
? null
103+
: Convert.ChangeType(value, typeProperty.Type);
104+
105+
typeProperty.PropertyInfo.SetValue(obj, safeValue, null);
106+
}
107+
108+
list.Add(obj);
109+
}
110+
111+
return list;
112+
}
113+
114+
#if NET || NETSTANDARD2_0_OR_GREATER
115+
116+
/// <summary>
117+
/// A DataTable extension method that converts a table to a JSON.
118+
/// </summary>
119+
/// <typeparam name="T">Generic type parameter.</typeparam>
120+
/// <param name="table">The table to act on.</param>
121+
/// <returns>
122+
/// DataTable as a JSON string.
123+
/// </returns>
124+
public static string ToJson<T>(this DataTable table) where T : new()
125+
{
126+
return JsonObjectSerializer.ToString(table.ToList<T>());
127+
}
128+
129+
/// <summary>
130+
/// A DataTable extension method that converts a table to a JSON.
131+
/// </summary>
132+
/// <param name="table">The table to act on.</param>
133+
/// <returns>
134+
/// DataTable as a JSON string.
135+
/// </returns>
136+
public static string ToJson(this DataTable table)
137+
{
138+
var columnCount = table.Columns.Count;
139+
var types = new Type[columnCount];
140+
var names = new string[columnCount];
141+
142+
for (var i = 0; i < columnCount; i++)
143+
{
144+
types[i] = table.Columns[i].DataType;
145+
names[i] = table.Columns[i].ColumnName;
146+
}
147+
148+
var type = AnonymousClassFactory.CreateType(types, names, true);
149+
var list = table.ToList(type);
150+
151+
return JsonObjectSerializer.ToString(list);
152+
}
153+
#endif
68154
}
69155
}

src/DomainCommonExtensions/DataTypeExtensions/EnumExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
using System.Runtime.Serialization;
2929
#endif
3030

31+
// ReSharper disable RedundantCast
32+
3133
#endregion
3234

3335
namespace DomainCommonExtensions.DataTypeExtensions
@@ -234,5 +236,17 @@ public static string GetDisplayDescription(this Enum value)
234236
return value.ToString();
235237
}
236238
#endif
239+
240+
/// <summary>
241+
/// A T extension method that determine if we are equals.
242+
/// </summary>
243+
/// <typeparam name="T">Generic type parameter.</typeparam>
244+
/// <param name="sourceEnumValue">The sourceEnumValue to act on.</param>
245+
/// <param name="compareEnumValue">The compare enum value.</param>
246+
/// <returns>
247+
/// True if equals, false if not.
248+
/// </returns>
249+
public static bool AreEquals<T>(this T sourceEnumValue, T compareEnumValue) where T : Enum, IComparable, IFormattable
250+
=> Equals(sourceEnumValue, compareEnumValue);
237251
}
238252
}

0 commit comments

Comments
 (0)