Skip to content

Commit

Permalink
Adjust/clean up code execution. Add new extens
Browse files Browse the repository at this point in the history
Adjust and clean up code execution.
Reorganize typeparam extensions.
Add new typeparam extensions.
  • Loading branch information
I-RzR-I committed Feb 13, 2024
1 parent e3c57b0 commit 22c753e
Show file tree
Hide file tree
Showing 22 changed files with 732 additions and 120 deletions.
47 changes: 26 additions & 21 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
### **v.1.0.1.0823**
### **v1.0.1.0823**
-> Was fixed tests and was added validator for input source.<br />
-> Was added `ToEnum<T>` from the string.<br />
-> Was added check methods `IsTypeOfNullableInt`, `IsTypeOfFloatingPoint`, `IsTypeOfNullableFloatingPoint` from property type.

### **v.1.0.1.1842**
### **v1.0.1.1842**
-> Was added new byte extension: `ToStringFromByteUnicode`, `ToHexByte`.<br />
-> Was added new string extension: `ToBytesUnicode`.

### **v.1.0.2.1107**
### **v1.0.2.1107**
-> Was added new DateTime extension: `StartOfWeek`, `EndOfWeek`, `StartOfMonth`, `EndOfMonth`, `StartOfPreviousMonth`, `EndOfPreviousMonth`, `StartOfYear`, `EndOfYear`, `DaysInMonth`, `DaysInYear`, `GetIso8601WeekOfYear`.<br />
-> Was added new string extension: `ReplaceExact`.<br />
-> Was added new Exception extension: `GetFullError`.<br />
-> Was added new ExpandoObject extension: `AddProperty`, `UpdateValue`, `GetValue`.

### **v.1.0.2.1457**
### **v1.0.2.1457**
-> Was added new string extension: `IfNullOrWhiteSpace`, `IfNullOrEmpty`.<br />
-> Was added new TExtensions extension: `IfNotNull`.

### **v.1.0.3.0**
### **v1.0.3.0**
-> Was renamed `Utils` to `GeneralUtils`.<br />
-> Was added new `EnumerateUtils` with methods: `FromTo<int>`, `FromTo<DateTime>` and `PowersOf`.<br />
-> Was added new `DirectoryHelper` with methods: `CreateDirectory`, `CopyDirectory` and `DeleteDirectory`.<br />
Expand All @@ -42,61 +42,66 @@
-> 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 />
-> Was added new `ArrayExtensions` with methods: `IndexOf`.<br />

### **v.1.0.3.1101**
### **v1.0.3.1101**
-> Was added new object extension: `SerializeToString` .<br />
-> Was added new string extension: `DeserializeToObject` .<br />
-> Was added new T extension: `SerializeToXmlDoc` .<br />

### **v.1.0.4.1925**
### **v1.0.4.1925**
-> Added support for net framework.<br />

### **v.1.0.5.1849**
### **v1.0.5.1849**
-> Added string extension `Contains`.<br />
-> Added int/long extension `IsLessZero`.<br />
-> Was added new Type extension: `GetStringPropertyNames`, `GetStringPropertyInfos`, `GetPropertyInfos`.<br />

### **v.1.0.5.2131**
### **v1.0.5.2131**
-> Added string extension `ParseToInt`, `ParseNullableInt`, `TryParseInt`.<br />
-> Added list extension `ActionForEach`.<br />

### **v.1.0.6.1341**
### **v1.0.6.1341**
-> Update vulnerable library version.<br />

### **v.1.0.7.0535**
### **v1.0.7.0535**
-> Add in directory helper new methods: `FileCount` x3, `DirectoryFileCount`.<br />

### **v.1.0.8.0638**
### **v1.0.8.0638**
-> Added string extension `GetHashSha512String`, `FromSpaceSeparatedString`, `IsMissing`, `IsNullOrEmpty`, `AddQueryString`, `AddHashFragment`, `GetOrigin`, `Obfuscate`.<br />
-> Added Enumerable extension `ToSpaceSeparatedString`, `HasDuplicates`, `GetDuplicates`.<br />

### **v.1.0.9.2108**
### **v1.0.9.2108**
-> Added object extensions `ThrowIfArgNull`, `ThrowArgIfNull`.<br />
-> Added bool extensions `IsTrue`, `IsFalse`.<br />
-> Added null check extensions `IsNotNull`, `IsDbNull`.<br />
-> Added string extensions `ThrowArgIfNull`, `ThrowArgIfNullOrEmpty`, `ThrowIfArgNull`, `ThrowIfArgNullOrEmpty`.<br />
-> Adjust validation for input params at some methods.
-> Small code refactor.

### **v.1.0.10.2315**
### **v1.0.10.2315**
-> Update lib version. Add option to sign the new version of the files.<br />
-> Small code refactor.

### **v.1.0.11.1319**
### **v1.0.11.1319**
-> Fix wrong modification.<br />

### **v.1.0.12.1447**
### **v1.0.12.1447**
-> Add IDataReader extensions to convert object in specific type.<br />

### **v.1.0.13.8399**
### **v1.0.13.8399**
-> Add excel column name generator `GetExcelColumnName`.<br />
-> Adjust method modifier for `GetDuplicates`.<br />
-> Fix tests.

### **v.1.0.14.6517**
### **v1.0.14.6517**
-> Fix some enums extensions.<br />
-> Add new methods (`AppendTo`, `GetPropertiesInfoFromSource`) in 'TExtensions'.
-> Add new methods (`AppendTo`, `GetPropertiesInfoFromSource`) in `TExtensions`.

### **v.1.1.0.0**
### **v1.1.0.0**
-> Remove unused packages.<br />
-> Downgrade some package versions to cover target frameworks.<br />
-> Fix some warnings and disposable objects.<br />
-> Fix some warnings and disposable objects.<br />

### **v1.1.1.7310**
-> Adjust and clean up code execution.<br />
-> Reorganize typeparam extensions.<br />
-> Add new typeparam extensions: `IfIsNull`, `IfIsNotNull`, `IfIsNullOrFuncIsTrue`, `IfIsNullAndFuncIsTrue`, `IfFuncIsTrue`, `IfFuncIsFalse`, `IfFunc`, `IfNull`, `IfNotNull`.<br />
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
// </summary>
// ***********************************************************************

#region U S A G E S

#endregion

namespace DomainCommonExtensions.ArraysExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using DomainCommonExtensions.DataTypeExtensions;

#endregion

Expand All @@ -42,7 +43,7 @@ public static Dictionary<TKey, TValue> AddRange<TKey, TValue>(this Dictionary<TK
{
context ??= new Dictionary<TKey, TValue>();
foreach (var item in newItems)
if (context.ContainsKey(item.Key))
if (context.ContainsKey(item.Key).IsTrue())
context[item.Key] = item.Value;
else
context.Add(item.Key, item.Value);
Expand All @@ -62,7 +63,7 @@ public static Dictionary<TKey, TValue> RemoveKeys<TKey, TValue>(this Dictionary<
IEnumerable<TKey> keys)
{
foreach (var key in keys)
if (dict.ContainsKey(key))
if (dict.ContainsKey(key).IsTrue())
dict.Remove(key);

return dict;
Expand Down Expand Up @@ -94,7 +95,7 @@ public static int IndexOf(this IDictionary dictionary, object value)
public static string GetStringOrDefault(this Dictionary<string, string> dictionary, string key,
string @default = default)
{
if (dictionary.ContainsKey(key)) return dictionary[key];
if (dictionary.ContainsKey(key).IsTrue()) return dictionary[key];

return @default;
}
Expand All @@ -110,7 +111,7 @@ public static string GetStringOrDefault(this Dictionary<string, string> dictiona
public static Guid GetGuidOrDefault(this Dictionary<string, string> dictionary, string key,
Guid @default = default)
{
if (dictionary.ContainsKey(key))
if (dictionary.ContainsKey(key).IsTrue())
if (Guid.TryParse(dictionary[key], out var value))
return value;

Expand All @@ -128,7 +129,7 @@ public static Guid GetGuidOrDefault(this Dictionary<string, string> dictionary,
public static int GetIntOrDefault(this Dictionary<string, string> dictionary, string key,
int @default = default)
{
if (dictionary.ContainsKey(key))
if (dictionary.ContainsKey(key).IsTrue())
if (int.TryParse(dictionary[key], out var value))
return value;

Expand All @@ -146,7 +147,7 @@ public static int GetIntOrDefault(this Dictionary<string, string> dictionary, st
public static bool GetBoolOrDefault(this Dictionary<string, string> dictionary, string key,
bool @default = default)
{
if (dictionary.ContainsKey(key))
if (dictionary.ContainsKey(key).IsTrue())
if (bool.TryParse(dictionary[key], out var value))
return value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using System.Text;
using DomainCommonExtensions.CommonExtensions;
using System.Data;
using DomainCommonExtensions.CommonExtensions.TypeParam;
using DomainCommonExtensions.DataTypeExtensions;

namespace DomainCommonExtensions.ArraysExtensions
{
Expand Down Expand Up @@ -194,9 +196,9 @@ public static IEnumerable<T> Randomize<T>(this IEnumerable<T> target)
public static IEnumerable<IEnumerable<T>> Transpose<T>(this IEnumerable<IEnumerable<T>> collection)
{
var values = collection?.ToList() ?? new List<IEnumerable<T>>();
if (!values.Any())
if (values.IsNullOrEmptyEnumerable())
return values;
if (!values.First().Any())
if (values.First().IsNullOrEmptyEnumerable())
return Transpose(values.Skip(1));

var x = values.First().First();
Expand Down Expand Up @@ -240,8 +242,8 @@ public static Collection<T> ToCollection<T>(this IEnumerable<T> enumerable)
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> source, int select,
bool repetition = false)
{
Contract.Requires(source != null);
Contract.Requires(select >= 0);
Contract.Requires(source.IsNotNull());
Contract.Requires(select.IsGreaterThanOrEqualZero());

var enumerable = source.ToList();

Expand Down Expand Up @@ -351,7 +353,7 @@ public static string ListToString<T>(this IEnumerable<T> list, string delimiter)
// ReSharper disable PossibleMultipleEnumeration
var result = new StringBuilder();

if (!list.IsNull() && list.Any())
if (list.IsNotNull() && list.Any())
{
var notFirst = false;
foreach (var item in list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static string GetFullError(this Exception ex, bool showCallStack = true)
/// <remarks></remarks>
public static Exception WithData(this Exception ex, object dataKey, object dataValue)
{
if (!ex.Data.IsNull()) ex.Data[dataKey] = dataValue;
if (ex.Data.IsNotNull()) ex.Data[dataKey] = dataValue;

return ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using DomainCommonExtensions.DataTypeExtensions;

namespace DomainCommonExtensions.CommonExtensions
{
Expand All @@ -37,7 +38,7 @@ public static void AddProperty(this ExpandoObject expando, string propertyName,
{
// ExpandoObject supports IDictionary so we can extend it like this
var expandoDict = expando as IDictionary<string, object>;
if (expandoDict.ContainsKey(propertyName))
if (expandoDict.ContainsKey(propertyName).IsTrue())
expandoDict[propertyName] = propertyValue;
else
expandoDict.Add(propertyName, propertyValue);
Expand All @@ -53,7 +54,7 @@ public static void AddProperty(this ExpandoObject expando, string propertyName,
public static void UpdateValue(this ExpandoObject expando, string propertyName, object propertyValue)
{
var map = (IDictionary<string, object>)expando;
if (map.ContainsKey(propertyName))
if (map.ContainsKey(propertyName).IsTrue())
map[propertyName] = propertyValue;
foreach (var val in map.Values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static Expression<Func<T, bool>> AndAlso<T>(
Expression.Invoke(expr2, param)), param);
}


/// <summary>
/// Convert all expressions to 'AND' clause
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#region U S A G E S

using System.IO;
using DomainCommonExtensions.DataTypeExtensions;

#endregion

Expand All @@ -41,7 +42,7 @@ public static bool IsFileInUse(this string path)
using var fs = new FileStream(path, FileMode.OpenOrCreate);
var canWrite = fs.CanWrite;

return canWrite != true;
return canWrite.IsFalse();
}
catch (IOException)
{
Expand Down
8 changes: 4 additions & 4 deletions src/DomainCommonExtensions/CommonExtensions/NullExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public static bool IsNull(this object obj)
/// <summary>
/// Check if KeyValue is null
/// </summary>
/// <typeparam name="TK"></typeparam>
/// <typeparam name="TV"></typeparam>
/// <typeparam name="Tk"></typeparam>
/// <typeparam name="Tv"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsNull<TK, TV>(this KeyValuePair<TK, TV> source)
public static bool IsNull<Tk, Tv>(this KeyValuePair<Tk, Tv> source)
{
return source.Equals(default(KeyValuePair<TK, TV>));
return source.Equals(default(KeyValuePair<Tk, Tv>));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// ***********************************************************************
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
// Author : RzR
// Created On : 2024-02-13 19:42
//
// Last Modified By : RzR
// Last Modified On : 2024-02-13 20:02
// ***********************************************************************
// <copyright file="TypeParamActionExtensions.cs" company="">
// Copyright (c) RzR. All rights reserved.
// </copyright>
//
// <summary>
// </summary>
// ***********************************************************************

#region U S A G E S

using System;

#endregion

namespace DomainCommonExtensions.CommonExtensions.TypeParam
{
/// -------------------------------------------------------------------------------------------------
/// <content>
/// T type extensions.
/// </content>
/// =================================================================================================
public static partial class TExtensions
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Return data if not null.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Thrown when one or more required arguments are null.
/// </exception>
/// <typeparam name="TInput">Input type.</typeparam>
/// <param name="source">Source data.</param>
/// <param name="action">Action.</param>
/// =================================================================================================
public static void IfNotNull<TInput>(this TInput source, Action<TInput> action)
{
if (action.IsNull())
throw new ArgumentNullException(nameof(action));

if (source.IsNull())
return;

action(source);
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Return data if null.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Thrown when one or more required arguments are null.
/// </exception>
/// <typeparam name="TInput">Input type.</typeparam>
/// <param name="source">Source data.</param>
/// <param name="action">Action.</param>
/// =================================================================================================
public static void IfNull<TInput>(this TInput source, Action<TInput> action)
{
if (action.IsNull())
throw new ArgumentNullException(nameof(action));

if (source.IsNull())
action(source);
}
}
}
Loading

0 comments on commit 22c753e

Please sign in to comment.