Skip to content

Commit f6915e6

Browse files
authored
Merge pull request #35 from I-RzR-I/feature/RefactorCodeReflectionExtensions
Feature/refactor code reflection extensions
2 parents 79d9ff6 + b8bd8b3 commit f6915e6

44 files changed

Lines changed: 1944 additions & 335 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### **v3.0.0.3007** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 07-08-2025
2+
* [9e7a5e9] (RzR) -> Auto commit uncommited files.
3+
* [ddc61a0] (RzR) -> Add new reflection extension methods (available from net45 and up); `GetTypes`, `GetSetMethod`, `GetGetMethod`, `GetGenericArguments`, `GetMethod`, `GetMembers`, `GetInterfaces`, `IsGenericType`, `IsValueType`, `IsAbstract`, `IsAssignableFrom`, `ContainsGenericParameters`, `BaseType`, `IsGenericTypeDefinition`, `IsPrimitive`, `IsNestedPublic`, `IsPublic`, `IsSealed`, `GetGenericParameterConstraints`, `IsClass`, `IsInterface`, `IsGenericParameter`, `GetGenericParameterAttributes`, `GetAssembly`, `GetConstructors`, `GetConstructor`, `IsInNamespace`.
4+
* [379d971] (RzR) -> Add `NotNull` (safe) array extension. Add array/enumerable tests.
5+
* [efb7a14] (RzR) -> Small code adjustments and improvements
6+
* [c4ec2f8] (RzR) -> Add tests for `DomainEnsure` methods
7+
* [780f3f5] (RzR) -> Adjust code to use `Ensure`. Adjust namespace.
8+
* [716c5a4] (RzR) -> [**BreakingChanges**] Relocate extension classes `ReflectionExtensions`, `TypeBuilderExtensions` and `TypeExtensions`.
9+
* [ad66c6d] (RzR) -> Adjust code to use defined extensions. Adjust namespace.
10+
* [6e57990] (RzR) -> Add collection extension method `With` (accept array).
11+
* [5db737c] (RzR) -> Add `Ensure` methods and refactor code.
12+
113
### **v2.3.0.7698** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 15-07-2025
214
* [f300bd2] (RzR) -> Auto commit uncommited files
315
* [067dd42] (RzR) -> Add alternative extension method for `WithIndex`

src/DomainCommonExtensions/ArraysExtensions/ArrayExtensions.cs

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

17-
using System;
18-
using System.Linq;
17+
#region U S A G E S
18+
1919
using DomainCommonExtensions.CommonExtensions;
2020
using DomainCommonExtensions.DataTypeExtensions;
21+
using System;
22+
using System.Linq;
23+
24+
#endregion
2125

2226
namespace DomainCommonExtensions.ArraysExtensions
2327
{
@@ -165,7 +169,7 @@ public static T[] AppendIfNotExists<T>(this T[] source, T[] itemsToAppend)
165169
/// =================================================================================================
166170
public static T[] RemoveItem<T>(this T[] source, T item)
167171
{
168-
if (source.IsNullOrEmptyEnumerable()) return new T[] { };
172+
if (source.IsNullOrEmptyEnumerable()) return new T[] { };
169173
if (item.IsNull()) return source;
170174

171175
var idx = source.IndexOf(item);
@@ -186,7 +190,7 @@ public static T[] RemoveItem<T>(this T[] source, T item)
186190
/// =================================================================================================
187191
public static T[] RemoveAtIdx<T>(this T[] source, int index)
188192
{
189-
if (source.IsNullOrEmptyEnumerable()) return new T[] { };
193+
if (source.IsNullOrEmptyEnumerable()) return new T[] { };
190194
if (index.IsLessZero()) return source;
191195

192196
T[] dest = new T[source.Length - 1];
@@ -198,5 +202,17 @@ public static T[] RemoveAtIdx<T>(this T[] source, int index)
198202

199203
return dest;
200204
}
205+
206+
/// <summary>
207+
/// Not null array
208+
/// </summary>
209+
/// <param name="array">Input array</param>
210+
/// <returns></returns>
211+
/// <typeparam name="T">Array type</typeparam>
212+
/// <remarks></remarks>
213+
public static T[] NotNull<T>(this T[] array)
214+
{
215+
return array ?? new T[] { };
216+
}
201217
}
202218
}

src/DomainCommonExtensions/ArraysExtensions/CollectionExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ public static ICollection<T> With<T>(this ICollection<T> source, T item)
9999
return source;
100100
}
101101

102+
/// <summary>
103+
/// Add given items to source collection
104+
/// </summary>
105+
/// <param name="source">Source collection</param>
106+
/// <param name="items">Items to add</param>
107+
/// <returns></returns>
108+
/// <typeparam name="T">Collection type</typeparam>
109+
/// <remarks></remarks>
110+
public static ICollection<T> With<T>(this ICollection<T> source, T[] items)
111+
{
112+
source.AddRange(items);
113+
114+
return source;
115+
}
116+
102117
/// <summary>
103118
/// Remove given item to source collection
104119
/// </summary>

src/DomainCommonExtensions/ArraysExtensions/DynamicListExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using System.Collections.Generic;
2020
using System.Linq;
2121
using System.Linq.Expressions;
22-
using DomainCommonExtensions.CommonExtensions;
22+
using DomainCommonExtensions.CommonExtensions.Reflection;
2323
using DomainCommonExtensions.Helpers.Internal.AnonymousSelect;
2424

2525
#region OLD Using System.Linq.Dynamic.Core
@@ -112,6 +112,7 @@ public static IList<dynamic> ParseListOfTInDynamic<T>(this List<T> input, IEnume
112112

113113
return result.Cast<dynamic>().ToList();
114114
}
115+
115116
/// <summary>
116117
/// Parse input data (List) to dynamic result (list)
117118
/// </summary>

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
// </summary>
1515
// ***********************************************************************
1616

17+
#region U S A G E S
18+
1719
using DomainCommonExtensions.CommonExtensions;
20+
using DomainCommonExtensions.CommonExtensions.Reflection;
1821
using DomainCommonExtensions.CommonExtensions.TypeParam;
1922
using DomainCommonExtensions.DataTypeExtensions;
2023
using DomainCommonExtensions.Models;
@@ -30,6 +33,8 @@
3033
// ReSharper disable UnusedParameter.Local
3134
// ReSharper restore PossibleMultipleEnumeration
3235

36+
#endregion
37+
3338
namespace DomainCommonExtensions.ArraysExtensions
3439
{
3540
/// <summary>
@@ -76,7 +81,7 @@ public static string Join(this IEnumerable<string> source, string separator)
7681
public static bool IsLast<T>(this IEnumerable<T> items, T item)
7782
{
7883
var list = items?.ToList() ?? new List<T>();
79-
if (!list.Any())
84+
if (list.IsNullOrEmptyEnumerable())
8085
return false;
8186
var last = list.ElementAt(list.Count - 1);
8287

@@ -93,7 +98,7 @@ public static bool IsLast<T>(this IEnumerable<T> items, T item)
9398
public static bool IsFirst<T>(this IEnumerable<T> items, T item)
9499
{
95100
var list = items?.ToList() ?? new List<T>();
96-
if (!list.Any())
101+
if (list.IsNullOrEmptyEnumerable())
97102
return false;
98103
var first = list.FirstOrDefault();
99104

@@ -135,7 +140,7 @@ public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnume
135140
var enumeratedSource = source.ToList();
136141
var enumeratedTarget = target.ToList();
137142

138-
if (!enumeratedSource.Any() || !enumeratedTarget.Any()) return false;
143+
if (enumeratedSource.IsNullOrEmptyEnumerable() || enumeratedTarget.IsNullOrEmptyEnumerable()) return false;
139144
var common = enumeratedSource.Intersect(enumeratedTarget);
140145

141146
return common.Any();

src/DomainCommonExtensions/CommonExtensions/Encryption/AESEncryptionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Security.Cryptography;
2424
using System.Text;
2525
using DomainCommonExtensions.DataTypeExtensions;
26+
using DomainCommonExtensions.Utilities.Ensure;
2627

2728
#endregion
2829

src/DomainCommonExtensions/CommonExtensions/Encryption/RSAEncryptionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Security.Cryptography.X509Certificates;
2121
using System.Text;
2222
using DomainCommonExtensions.DataTypeExtensions;
23+
using DomainCommonExtensions.Utilities.Ensure;
2324

2425
// ReSharper disable InconsistentNaming
2526
// ReSharper disable CheckNamespace

src/DomainCommonExtensions/CommonExtensions/FuncExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System;
2020
using System.Threading.Tasks;
2121
using DomainCommonExtensions.DataTypeExtensions;
22+
using DomainCommonExtensions.Utilities.Ensure;
2223

2324
#endregion
2425

@@ -73,8 +74,7 @@ public static bool IsFalse(this Func<bool> func)
7374
/// =================================================================================================
7475
public static bool IsTrue(this Func<Task<bool>> func)
7576
{
76-
if (func.IsNull())
77-
throw new ArgumentNullException(nameof(func));
77+
DomainEnsure.IsNotNull(func, nameof(func));
7878

7979
return func.Invoke().Result.IsTrue();
8080
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#if NET45_OR_GREATER || NET || NETSTANDARD1_0_OR_GREATER
2+
// ***********************************************************************
3+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
4+
// Author : RzR
5+
// Created On : 2025-08-06 21:42
6+
//
7+
// Last Modified By : RzR
8+
// Last Modified On : 2025-08-06 21:43
9+
// ***********************************************************************
10+
// <copyright file="AssemblyExtensions.cs" company="RzR SOFT & TECH">
11+
// Copyright © RzR. All rights reserved.
12+
// </copyright>
13+
//
14+
// <summary>
15+
// </summary>
16+
// ***********************************************************************
17+
18+
#region U S A G E S
19+
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Linq;
23+
using System.Reflection;
24+
25+
#endregion
26+
27+
namespace DomainCommonExtensions.CommonExtensions.Reflection
28+
{
29+
/// -------------------------------------------------------------------------------------------------
30+
/// <summary>
31+
/// An assembly extensions.
32+
/// </summary>
33+
/// <content>
34+
/// An assembly extensions.
35+
/// </content>
36+
/// =================================================================================================
37+
public static partial class AssemblyExtensions
38+
{
39+
/// -------------------------------------------------------------------------------------------------
40+
/// <summary>
41+
/// An Assembly extension method that gets the types.
42+
/// </summary>
43+
/// <param name="assembly">The assembly to act on.</param>
44+
/// <returns>
45+
/// An array of type.
46+
/// </returns>
47+
/// =================================================================================================
48+
public static IEnumerable<Type> GetTypes(this Assembly assembly)
49+
{
50+
return assembly.DefinedTypes.Select(i => i.AsType());
51+
}
52+
}
53+
}
54+
#endif
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#if NET45_OR_GREATER || NET || NETSTANDARD1_0_OR_GREATER
2+
// ***********************************************************************
3+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
4+
// Author : RzR
5+
// Created On : 2025-08-06 21:38
6+
//
7+
// Last Modified By : RzR
8+
// Last Modified On : 2025-08-06 21:38
9+
// ***********************************************************************
10+
// <copyright file="PropertyInfoExtensions.cs" company="RzR SOFT & TECH">
11+
// Copyright © RzR. All rights reserved.
12+
// </copyright>
13+
//
14+
// <summary>
15+
// </summary>
16+
// ***********************************************************************
17+
18+
#region U S A G E S
19+
20+
using System.Reflection;
21+
using DomainCommonExtensions.DataTypeExtensions;
22+
23+
#endregion
24+
25+
namespace DomainCommonExtensions.CommonExtensions.Reflection
26+
{
27+
/// -------------------------------------------------------------------------------------------------
28+
/// <summary>
29+
/// A property information extensions.
30+
/// </summary>
31+
/// <content>
32+
/// A property information extensions.
33+
/// </content>
34+
/// =================================================================================================
35+
public static partial class PropertyInfoExtensions
36+
{
37+
/// -------------------------------------------------------------------------------------------------
38+
/// <summary>
39+
/// A PropertyInfo extension method that gets 'SetMethod' method.
40+
/// </summary>
41+
/// <param name="property">The property to act on.</param>
42+
/// <param name="nonPublic">(Optional) True to non public.</param>
43+
/// <returns>
44+
/// The method 'SetMethod'.
45+
/// </returns>
46+
/// =================================================================================================
47+
public static MethodInfo GetSetMethod(this PropertyInfo property, bool nonPublic = true)
48+
{
49+
return nonPublic || (property.SetMethod?.IsPublic).IsTrue() ? property.SetMethod : null;
50+
}
51+
52+
/// -------------------------------------------------------------------------------------------------
53+
/// <summary>
54+
/// A PropertyInfo extension method that gets 'GetMethod' method.
55+
/// </summary>
56+
/// <param name="property">The property to act on.</param>
57+
/// <param name="nonPublic">(Optional) True to non public.</param>
58+
/// <returns>
59+
/// The method 'GetMethod'.
60+
/// </returns>
61+
/// =================================================================================================
62+
public static MethodInfo GetGetMethod(this PropertyInfo property, bool nonPublic = true)
63+
{
64+
return nonPublic || (property.GetMethod?.IsPublic).IsTrue() ? property.GetMethod : null;
65+
}
66+
}
67+
}
68+
#endif

0 commit comments

Comments
 (0)