Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: I-RzR-I/DomainCommonExtensions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0.0
Choose a base ref
...
head repository: I-RzR-I/DomainCommonExtensions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Feb 13, 2024

  1. Adjust/clean up code execution. Add new extens

    Adjust and clean up code execution.
    Reorganize typeparam extensions.
    Add new typeparam extensions.
    I-RzR-I committed Feb 13, 2024
    Copy the full SHA
    22c753e View commit details
  2. Merge pull request #24 from I-RzR-I/feature/AddIfNullOrXExtensions

    Adjust/clean up code execution. Add new extens
    I-RzR-I authored Feb 13, 2024
    Copy the full SHA
    93cbbd4 View commit details

Commits on May 18, 2024

  1. Copy the full SHA
    1ad9a46 View commit details
  2. Merge pull request #25 from I-RzR-I/feature/25042024AddNewExtension

    Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.
    I-RzR-I authored May 18, 2024
    Copy the full SHA
    1cd61e7 View commit details

Commits on May 29, 2024

  1. Copy the full SHA
    54df4f9 View commit details
  2. Adjust timespan extensions

    I-RzR-I committed May 29, 2024
    Copy the full SHA
    4daeca6 View commit details
  3. Copy the full SHA
    ca1a8f7 View commit details
  4. Copy the full SHA
    669803a View commit details
  5. Copy the full SHA
    068b57b View commit details
  6. Copy the full SHA
    ad21080 View commit details
  7. Copy the full SHA
    19eb7ee View commit details
  8. Copy the full SHA
    3749789 View commit details
  9. Merge pull request #26 from I-RzR-I/feature/AddAndReviewValidation

    add and review validation in the DataTypeExtensions folder
    I-RzR-I authored May 29, 2024
    Copy the full SHA
    cbad95d View commit details

Commits on Sep 22, 2024

  1. Copy the full SHA
    3f963e6 View commit details
  2. Merge pull request #27 from I-RzR-I/feature/AddJsonValidation

    Fix test for `CalculateAge`. Add new string extensions.
    I-RzR-I authored Sep 22, 2024
    Copy the full SHA
    9a0adf4 View commit details

Commits on Jan 9, 2025

  1. Copy the full SHA
    cb55649 View commit details
  2. Copy the full SHA
    ad981ce View commit details
  3. Copy the full SHA
    99a4806 View commit details
  4. Fix DateTime extension 'CalculateAge'. Add new tests.

    Fix DateTime extension 'CalculateAge'.
    Add new tests for 'AsNotNull' methods.
    I-RzR-I committed Jan 9, 2025
    Copy the full SHA
    4067f4f View commit details
  5. Adjust dynamic property/ies select avoid System.Linq.Dynamic.Core

    Adjust and rebuild dynamic propert select and dynamic result avoiding package reference.
    I-RzR-I committed Jan 9, 2025
    Copy the full SHA
    ec39a31 View commit details
  6. Copy the full SHA
    5463c06 View commit details
  7. Copy the full SHA
    81302c7 View commit details
  8. Merge pull request #28 from I-RzR-I/feature/Remove_System_Linq_Dynami…

    …c_Core
    
    Feature/remove system linq dynamic core
    I-RzR-I authored Jan 9, 2025
    Copy the full SHA
    f3c9147 View commit details
  9. Remove unused package.

    I-RzR-I committed Jan 9, 2025
    Copy the full SHA
    d620b9a View commit details
  10. Copy the full SHA
    d6626cb View commit details
  11. Merge pull request #29 from I-RzR-I/fix/RemoveUnusedReference

    Fix/remove unused reference
    I-RzR-I authored Jan 9, 2025
    Copy the full SHA
    78cf008 View commit details
Showing with 2,837 additions and 167 deletions.
  1. +1 −1 LICENSE
  2. +1 −1 README.md
  3. +48 −21 docs/CHANGELOG.md
  4. +0 −4 src/DomainCommonExtensions/ArraysExtensions/ArrayExtensions.cs
  5. +7 −6 src/DomainCommonExtensions/ArraysExtensions/DictionaryExtensions.cs
  6. +109 −15 src/DomainCommonExtensions/ArraysExtensions/DynamicListExtensions.cs
  7. +10 −6 src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs
  8. +8 −9 src/DomainCommonExtensions/CommonExtensions/Encryption/AESEncryptionExtensions.cs
  9. +1 −1 src/DomainCommonExtensions/CommonExtensions/ExceptionExtensions.cs
  10. +3 −2 src/DomainCommonExtensions/CommonExtensions/ExpandoObjectExtensions.cs
  11. +0 −1 src/DomainCommonExtensions/CommonExtensions/ExpressionExtensions.cs
  12. +2 −1 src/DomainCommonExtensions/CommonExtensions/FilesExtensions.cs
  13. +4 −4 src/DomainCommonExtensions/CommonExtensions/NullExtensions.cs
  14. +1 −1 src/DomainCommonExtensions/CommonExtensions/ReflectionExtensions.cs
  15. +106 −0 src/DomainCommonExtensions/CommonExtensions/TypeBuilderExtensions.cs
  16. +3 −0 src/DomainCommonExtensions/CommonExtensions/TypeExtensions.cs
  17. +74 −0 src/DomainCommonExtensions/CommonExtensions/TypeParam/TypeParamActionExtensions.cs
  18. +41 −60 src/DomainCommonExtensions/CommonExtensions/{TExtensions.cs → TypeParam/TypeParamExtensions.cs}
  19. +325 −0 src/DomainCommonExtensions/CommonExtensions/TypeParam/TypeParamFuncExtensions.cs
  20. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToBoolExtensions.cs
  21. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToByteExtensions.cs
  22. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToCharExtensions.cs
  23. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToDateTimeExtensions.cs
  24. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToDecimalExtensions.cs
  25. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToDoubleExtensions.cs
  26. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToFloatExtensions.cs
  27. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToGuidExtensions.cs
  28. +2 −0 src/DomainCommonExtensions/ConvertExtensions/DataReader/ToIntExtensions.cs
  29. +11 −0 src/DomainCommonExtensions/DataTypeExtensions/ByteExtensions.cs
  30. +15 −1 src/DomainCommonExtensions/DataTypeExtensions/DateTimeExtensions.cs
  31. +12 −1 src/DomainCommonExtensions/DataTypeExtensions/DecimalExtensions.cs
  32. +21 −12 src/DomainCommonExtensions/DataTypeExtensions/EnumExtensions.cs
  33. +12 −1 src/DomainCommonExtensions/DataTypeExtensions/IntExtensions.cs
  34. +11 −0 src/DomainCommonExtensions/DataTypeExtensions/LongExtensions.cs
  35. +11 −0 src/DomainCommonExtensions/DataTypeExtensions/ObjectExtensions.cs
  36. +4 −0 src/DomainCommonExtensions/DataTypeExtensions/SocketExtensions.cs
  37. +198 −11 src/DomainCommonExtensions/DataTypeExtensions/StringExtensions.cs
  38. +14 −0 src/DomainCommonExtensions/DataTypeExtensions/StringInjectExtension.cs
  39. +3 −0 src/DomainCommonExtensions/DataTypeExtensions/TimeSpanExtension.cs
  40. +9 −2 src/DomainCommonExtensions/DomainCommonExtensions.csproj
  41. +1 −1 src/DomainCommonExtensions/Helpers/InsensitiveCaseHashtableHelper.cs
  42. +223 −0 src/DomainCommonExtensions/Helpers/Internal/AnonymousSelect/Base/AnonymousClass.cs
  43. +178 −0 src/DomainCommonExtensions/Helpers/Internal/AnonymousSelect/ExpressionHelper.cs
  44. +553 −0 src/DomainCommonExtensions/Helpers/Internal/AnonymousSelect/Factory/AnonymousClassFactory.cs
  45. +59 −0 src/DomainCommonExtensions/Helpers/Internal/AnonymousSelect/Factory/AssemblyBuilderFactory.cs
  46. +4 −4 src/shared/GeneralAssemblyInfo.cs
  47. +79 −0 src/tests/DataTypeTests/CryptoExtensionsTests.cs
  48. +31 −1 src/tests/DataTypeTests/DateTimeTests.cs
  49. +289 −0 src/tests/DataTypeTests/DynamicListTests.cs
  50. +71 −0 src/tests/DataTypeTests/EnumerateUtilsTests.cs
  51. +25 −0 src/tests/DataTypeTests/Models/RecordType.cs
  52. +45 −0 src/tests/DataTypeTests/Models/TempModel.cs
  53. +33 −0 src/tests/DataTypeTests/StringTests.cs
  54. +163 −0 src/tests/DataTypeTests/TypeParamTests.cs
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2024 RzR
Copyright (c) 2022-2025 RzR

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
[![NuGet Version](https://img.shields.io/nuget/v/DomainCommonExtensions.svg?style=flat&logo=nuget)](https://www.nuget.org/packages/DomainCommonExtensions/)
[![Nuget Downloads](https://img.shields.io/nuget/dt/DomainCommonExtensions.svg?style=flat&logo=nuget)](https://www.nuget.org/packages/DomainCommonExtensions)

This library/ repository was created as a way to simplify the development process. Here were written the usually used methods (extension methods) for some data types like `int, string, DateTime, Enum, bool, byte, Guid`, also there was added extensions for `List, Dictionary, DynamicList(using 'System.Linq.Dynamic.Core')` and other collections(`ICollection, IEnumerable, IList, HashSet, IQueryable`).
This library/ repository was created as a way to simplify the development process. Here were written the usually used methods (extension methods) for some data types like `int, string, DateTime, Enum, bool, byte, Guid`, also there was added extensions for `List, Dictionary, DynamicList` and other collections(`ICollection, IEnumerable, IList, HashSet, IQueryable`).

In the repository was added an extension for `cryptography`, encrypting and decrypting string by key with RSA.

69 changes: 48 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 />
@@ -42,61 +42,88 @@
-> 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 />

### **v1.1.2.3434**
-> Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.<br />

### **v1.2.0.0**
-> Add/adjust input validations in the `DataTypeExtensions` foler with extensions;<br />
-> Add new string extensions: `IfNullThenEmpty`.<br />

### **v1.3.0.0**
-> Fix test for `CalculateAge`;<br />
-> Add new string extensions: `IsValidJson`, `IsValidJsonObject`, `IsValidJsonArray`;<br />

### **v2.0.0.0**
-> Fix test for `CalculateAge`;<br />
-> Add DateTime extension method `AsNotNull`;<br />
-> Add new tests for `AsNotNull` methods;<br />
-> Add `EnumerateUtils` enumerable utils some tests;<br />
-> Adjust AES encryption(`AesEncryptString`, `AesDecryptString`) and expose iv as input;<br />
-> Adjust dynamic property/ies select avoid `System.Linq.Dynamic.Core`;<br />

### **v2.0.1.8588**
-> Remove unused package `Microsoft.CodeAnalysis.Common`;<br />
Original file line number Diff line number Diff line change
@@ -14,10 +14,6 @@
// </summary>
// ***********************************************************************

#region U S A G E S

#endregion

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

#endregion

@@ -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);
@@ -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;
@@ -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;
}
@@ -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;

@@ -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;

@@ -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;

124 changes: 109 additions & 15 deletions src/DomainCommonExtensions/ArraysExtensions/DynamicListExtensions.cs
Original file line number Diff line number Diff line change
@@ -18,9 +18,14 @@

using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using DomainCommonExtensions.CommonExtensions;
using DomainCommonExtensions.Helpers.Internal.AnonymousSelect;

#region OLD Using System.Linq.Dynamic.Core
//using System.Linq.Dynamic.Core;
//using System.Linq.Dynamic.Core.Parser;
#endregion

#endregion

@@ -32,8 +37,57 @@ namespace DomainCommonExtensions.ArraysExtensions
/// <remarks></remarks>
public static class DynamicListExtensions
{
#region OLD Using System.Linq.Dynamic.Core

/*
// Using System.Linq.Dynamic.Core
// // <summary>
// // Parse input data (List) to dynamic result (list)
// // </summary>
// // <param name="input">List of T input data</param>
// // <param name="fields">Required fields</param>
// // <returns></returns>
// // <typeparam name="T"></typeparam>
// // <remarks></remarks>
// public static IList<dynamic> ParseListOfTInDynamic<T>(this List<T> input, IEnumerable<string> fields = null)
// {
// var data = input.AsQueryable();
// var requiredFields = typeof(T).GetSelectedFieldFromEntity(fields);
//
// var result = data.Select("new {" + requiredFields + "}").ToDynamicList();
//
// return result;
// }
*/

/*
// Using System.Linq.Dynamic.Core
// /// <summary>
// /// Parse input data (IEnumerable) to dynamic result (list)
// /// </summary>
// /// <param name="input">IEnumerable of T input data</param>
// /// <param name="fields">Required fields</param>
// /// <returns></returns>
// /// <typeparam name="T"></typeparam>
// /// <remarks></remarks>
// public static IList<dynamic> ParseEnumerableOfTInDynamic<T>(this IEnumerable<T> input,
// IEnumerable<string> fields = null)
// {
// var data = input.AsQueryable();
// var requiredFields = typeof(T).GetSelectedFieldFromEntity(fields);
// var result = data.Select("new {" + requiredFields + "}").ToDynamicList();
// return result;
// }
*/

#endregion

/// <summary>
/// Parse input data (List) to dynamic result (list)
/// Parse input data (IEnumerable) to dynamic result (list)
/// </summary>
/// <param name="input">List of T input data</param>
/// <param name="fields">Required fields</param>
@@ -44,29 +98,45 @@ public static IList<dynamic> ParseListOfTInDynamic<T>(this List<T> input, IEnume
{
var data = input.AsQueryable();
var requiredFields = typeof(T).GetSelectedFieldFromEntity(fields);
var parameter = Expression.Parameter(data.ElementType, "x");
var lambdaExpression = ExpressionHelper.ParseLambda(parameter, data.ElementType, false, requiredFields.Split(','));

var selectCall = Expression.Call(
typeof(Queryable),
"Select",
new[] { parameter.Type, lambdaExpression.Body.Type/*source.ElementType*/ },
data.Expression,
Expression.Quote(lambdaExpression));

var result = data.Select("new {" + requiredFields + "}").ToDynamicList();
var result = data.Provider.CreateQuery(selectCall);

return result;
return result.Cast<dynamic>().ToList();
}

/// <summary>
/// Parse input data (IEnumerable) to dynamic result (list)
/// Parse input data (List) to dynamic result (list)
/// </summary>
/// <param name="input">IEnumerable of T input data</param>
/// <param name="fields">Required fields</param>
/// <returns></returns>
/// <typeparam name="T"></typeparam>
/// <remarks></remarks>
public static IList<dynamic> ParseEnumerableOfTInDynamic<T>(this IEnumerable<T> input,
IEnumerable<string> fields = null)
public static IList<dynamic> ParseEnumerableOfTInDynamic<T>(this IEnumerable<T> input, IEnumerable<string> fields = null)
{
var data = input.AsQueryable();
var requiredFields = typeof(T).GetSelectedFieldFromEntity(fields);
var parameter = Expression.Parameter(data.ElementType, "x");
var lambdaExpression = ExpressionHelper.ParseLambda(parameter, data.ElementType, false, requiredFields.Split(','));

var result = data.Select("new {" + requiredFields + "}").ToDynamicList();
var selectCall = Expression.Call(
typeof(Queryable),
"Select",
new[] { parameter.Type, lambdaExpression.Body.Type/*source.ElementType*/ },
data.Expression,
Expression.Quote(lambdaExpression));

var result = data.Provider.CreateQuery(selectCall);

return result;
return result.Cast<dynamic>().ToList();
}

/// <summary>
@@ -79,12 +149,36 @@ public static IList<dynamic> ParseEnumerableOfTInDynamic<T>(this IEnumerable<T>
public static IQueryable SelectProperty(this IQueryable source, string prop)
{
var parameter = Expression.Parameter(source.ElementType, "x");
var property = prop.Split(',')
.Aggregate((Expression)parameter, Expression.Property);
var selector = Expression.Lambda(property, parameter);
var propEx = Expression.Property(parameter, prop);
var selector = Expression.Lambda(propEx, parameter);
var selectCall = Expression.Call(
typeof(Queryable),
"Select",
new[] { parameter.Type, propEx.Type },
source.Expression,
Expression.Quote(selector));

return source.Provider.CreateQuery(selectCall);
}

/// <summary>
/// Generate select multiple properties
/// </summary>
/// <param name="source">Data source IQueryable</param>
/// <param name="props">Properties name</param>
/// <returns></returns>
/// <remarks></remarks>
public static IQueryable SelectMultipleProperties(this IQueryable source, params string[] props)
{
var parameter = Expression.Parameter(source.ElementType, "x");
var lambdaExpression = ExpressionHelper.ParseLambda(parameter, source.ElementType, true, props);

var selectCall = Expression.Call(
typeof(Queryable), "Select", new[] { parameter.Type, property.Type },
source.Expression, Expression.Quote(selector));
typeof(Queryable),
"Select",
new[] { parameter.Type, lambdaExpression.Body.Type/*source.ElementType*/ },
source.Expression,
Expression.Quote(lambdaExpression));

return source.Provider.CreateQuery(selectCall);
}
Loading