Skip to content

Commit 651c1a8

Browse files
authored
Merge pull request #46 from I-RzR-I/feature/RandomInfoHelper
Feature/random info helper
2 parents aa4603c + b4c565a commit 651c1a8

19 files changed

Lines changed: 2702 additions & 18 deletions

docs/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### **v4.4.0.8476** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 19-01-2026
2+
* [0b54e4a] (RzR) -> Add `T` extension methods: `GetPropertyValue`, `GetPropertyStringValue`, `GetPropertyValue`, `ChangePropertyValue`.
3+
* [ee95f35] (RzR) -> Add `string` extension methods: `RemoveStartChars`, `RemoveEndChars`.
4+
* [e4334fe] (RzR) -> Add `Enum` extension method: `ToInt`.
5+
* [4bd5005] (RzR) -> Add multiple `Char` extension methods: `IsMissing`, `IsPresent`, `IsDigit`, `IsAscii`, `IsAsciiLetter`, `IsAsciiUpper`, `IsAsciiLower`, `IsNewLine`, `IsQuote`, `IsBracket`, `IsOperator`, `IsMathSign`, `IsWhiteSpaceFast`, `IsSymbolOrPunctuation`, `IsBinaryDigit`, `IsOctalDigit`, `IsHexDigit`, `ToHexValue`, `ToggleCase`, `IsPrintable`, `Next`, `Previous`, `IsEmoji`, `HasValue`, `DefaultIfNull`, `IsNullOrWhiteSpace`, `SpaceIfNull`.
6+
* [801e815] (RzR) -> Add multiple `TimeSpan` extension methods: `IsMissing`, `HasValidValue`, `IsZero`, `IsPositive`, `IsNegative`, `IsBetween`, `DefaultIfNull`, `ZeroIfNull`, `RoundUp`, `RoundDown`, `Clamp`, `TotalSecondsInt`, `TotalMinutesInt`, `TotalMillisecondsLong`, `ToClockFormat`, `ToHumanReadable`, `ThrowIfMissing`, `ThrowIfNegative`, `IsShorterThan`, `IsLongerThan`, `AddSafe`.
7+
* [d3fa3b4] (RzR) -> Add `Guid` extension method: `IsMissing`.
8+
* [46ae823] (RzR) -> Add multiple `RandomHelper` methods: `Long`, `Double`, `Decimal`, `Letter`, `Letters`, `LowerLetter`, `UpperLetter`, `AlphaNumeric`, `Digits`, `Guid`, `Token`, `DateTime`, `TimeSpan`, `Pick`, `Shuffle`, `Enum`.
9+
110
### **v4.3.0.6204** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 11-01-2026
211
* [09a89f2] (RzR) -> Add a type of indexed enumerable.
312

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+
// Author : RzR
4+
// Created On : 2026-01-19 22:01
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2026-01-19 22:42
8+
// ***********************************************************************
9+
// <copyright file="TypeParamEntityExtensions.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.Collections.Generic;
20+
using System.Linq;
21+
using DomainCommonExtensions.ArraysExtensions;
22+
using DomainCommonExtensions.Utilities.Ensure;
23+
24+
#endregion
25+
26+
namespace DomainCommonExtensions.CommonExtensions.TypeParam
27+
{
28+
/// -------------------------------------------------------------------------------------------------
29+
/// <content>
30+
/// T type extensions.
31+
/// </content>
32+
/// =================================================================================================
33+
public static partial class TExtensions
34+
{
35+
/// -------------------------------------------------------------------------------------------------
36+
/// <summary>
37+
/// Gets the property values in this collection.
38+
/// </summary>
39+
/// <typeparam name="TPropResultType">Type of the property result type.</typeparam>
40+
/// <typeparam name="TSourceEntity">Type of the source entity.</typeparam>
41+
/// <param name="source">The source to act on.</param>
42+
/// <param name="fieldNames">A variable-length parameters list containing field names.</param>
43+
/// <returns>
44+
/// An enumerator that allows foreach to be used to process the property values in this
45+
/// collection.
46+
/// </returns>
47+
/// =================================================================================================
48+
public static IEnumerable<TPropResultType> GetPropertyValue<TPropResultType, TSourceEntity>(this TSourceEntity source,
49+
params string[] fieldNames)
50+
where TPropResultType : struct
51+
where TSourceEntity : class
52+
{
53+
DomainEnsure.IsNotNull(source, nameof(source));
54+
55+
var resultList = new List<TPropResultType>();
56+
var props = source!.GetType().GetProperties().Where(x => fieldNames.Contains(x.Name));
57+
foreach (var prop in props.NotNull())
58+
{
59+
var value = prop.GetValue(source, null);
60+
if (value.IsNotNull())
61+
resultList.Add((TPropResultType)value!);
62+
}
63+
64+
return resultList;
65+
}
66+
67+
/// -------------------------------------------------------------------------------------------------
68+
/// <summary>
69+
/// Gets the property string values in this collection.
70+
/// </summary>
71+
/// <typeparam name="TSourceEntity">Type of the source entity.</typeparam>
72+
/// <param name="source">The source to act on.</param>
73+
/// <param name="fieldNames">A variable-length parameters list containing field names.</param>
74+
/// <returns>
75+
/// An enumerator that allows foreach to be used to process the property string values in
76+
/// this collection.
77+
/// </returns>
78+
/// =================================================================================================
79+
public static IEnumerable<string> GetPropertyStringValue<TSourceEntity>(this TSourceEntity source,
80+
params string[] fieldNames)
81+
where TSourceEntity : class
82+
{
83+
DomainEnsure.IsNotNull(source, nameof(source));
84+
85+
var resultList = new List<string>();
86+
var props = source!.GetType().GetProperties().Where(x => fieldNames.Contains(x.Name));
87+
foreach (var prop in props.NotNull())
88+
{
89+
var value = prop.GetValue(source, null);
90+
if (value.IsNotNull())
91+
resultList.Add(value!.ToString()!);
92+
}
93+
94+
return resultList;
95+
}
96+
97+
/// -------------------------------------------------------------------------------------------------
98+
/// <summary>
99+
/// Gets the property values in this collection.
100+
/// </summary>
101+
/// <typeparam name="TSourceEntity">Type of the source entity.</typeparam>
102+
/// <param name="source">The source to act on.</param>
103+
/// <param name="fieldNames">A variable-length parameters list containing field names.</param>
104+
/// <returns>
105+
/// An enumerator that allows foreach to be used to process the property values in this
106+
/// collection.
107+
/// </returns>
108+
/// =================================================================================================
109+
public static IEnumerable<object> GetPropertyValue<TSourceEntity>(this TSourceEntity source,
110+
params string[] fieldNames)
111+
where TSourceEntity : class
112+
{
113+
DomainEnsure.IsNotNull(source, nameof(source));
114+
115+
var resultList = new List<object>();
116+
var props = source!.GetType().GetProperties().Where(x => fieldNames.Contains(x.Name));
117+
foreach (var prop in props.NotNull())
118+
{
119+
var value = prop.GetValue(source, null);
120+
if (value.IsNotNull())
121+
resultList.Add(value!);
122+
}
123+
124+
return resultList;
125+
}
126+
127+
/// -------------------------------------------------------------------------------------------------
128+
/// <summary>
129+
/// A TEntityResult extension method that change property value.
130+
/// </summary>
131+
/// <typeparam name="TEntityResult">Type of the entity result.</typeparam>
132+
/// <typeparam name="TEntitySource">Type of the entity source.</typeparam>
133+
/// <param name="sourceResultEntry">The sourceResultEntry to act on.</param>
134+
/// <param name="sourceDataEntry">Source data entry.</param>
135+
/// <param name="propsName">A variable-length parameters list containing properties name.</param>
136+
/// <returns>
137+
/// A TEntityResult.
138+
/// </returns>
139+
/// =================================================================================================
140+
public static TEntityResult ChangePropertyValue<TEntityResult, TEntitySource>(
141+
this TEntityResult sourceResultEntry,
142+
TEntitySource sourceDataEntry, params string[] propsName)
143+
where TEntitySource : class
144+
where TEntityResult : class
145+
{
146+
DomainEnsure.IsNotNull(sourceResultEntry, nameof(sourceResultEntry));
147+
DomainEnsure.IsNotNull(sourceDataEntry, nameof(sourceDataEntry));
148+
149+
var props = sourceResultEntry!.GetType().GetProperties().Where(x => propsName.Contains(x.Name));
150+
foreach (var prop in props.NotNull())
151+
{
152+
var sourceEntryProp = sourceDataEntry.GetType().GetProperty(prop.Name);
153+
if (sourceEntryProp.IsNotNull())
154+
{
155+
var value = sourceEntryProp!.GetValue(sourceDataEntry, null);
156+
prop!.SetValue(sourceResultEntry, value, null);
157+
}
158+
}
159+
160+
return sourceResultEntry;
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)