Simple.Extensions
1.1.0
dotnet add package Simple.Extensions --version 1.1.0
NuGet\Install-Package Simple.Extensions -Version 1.1.0
<PackageReference Include="Simple.Extensions" Version="1.1.0" />
paket add Simple.Extensions --version 1.1.0
#r "nuget: Simple.Extensions, 1.1.0"
// Install Simple.Extensions as a Cake Addin #addin nuget:?package=Simple.Extensions&version=1.1.0 // Install Simple.Extensions as a Cake Tool #tool nuget:?package=Simple.Extensions&version=1.1.0
Simple Extensions
This library provides simple and very direct extensions on some basic types of C#, although it is simple it covers some functionality we need it all the time in many places which sometimes casue code duplication due to its simplicity.
My intension is to collect as much as I can of these simple functions and group them in single basic libray to help me and others in doing their tasks in an easy way.
This library is open source and covered with unit tests to ensure its stability and to be confident to use it in your projects.
In this first release I covered some functions on different C# types and alot is coming soon as well.
What covered now:
String Extensions:
Method | Description |
---|---|
IsEmpty() | Return true if the value is empty only otherwise return false |
IsNull() | Return true if the value is null only otherwise return false |
IsWhiteSpace() | Return true if the value is whitespace only otherwise return false |
HasValue() | Return true if the string has any value, it is simply a wrapper around IsNullOrWhiteSpace without the headache of negation |
HasSpecialCharacters() | Return true if the value contains any special character otherwise return false |
HasSpaces() | Return true if the value contains any whitespace otherwise return false |
HasSpecialCharactersOrSpaces() | Return true if the value contains any special character or spaces otherwise return false |
HasHTMLTags() | Returns true if the string has HTML tags, else returns false |
RemoveSpecialCharacters() | Remove any special characters in the string |
RemoveSpaces() | Remove any spaces in the string |
RemoveSpecialCharactersAndSpaces() | Remove any special characters or spaces in the string |
RemoveHTMLTags() | Remove any HTML tags from the string value |
IsValidUrl() | Return true if the value is valid url otherwise return false |
ExtractUrls() | Extract any valid url from the specified string |
IsValidEmail() | Return true if the value is valid email otherwise return false |
ExtractEmails() | Extract any valid email from the specified string |
FromJsonTo<T>() | Parses the text representing a single JSON value into a type |
DateTime Extensions:
Method | Description |
---|---|
ToUnixTimeStamp() | Convert any DateTime to unix timestamp |
GetDateRangeTo() | Create a DateTime range between from and to DateTime |
Long Extensions:
Method | Description |
---|---|
FromUnixTimeStampToDateTime() | Convert unix timestamp to valid DateTime |
Queryable Extensions:
Method | Description |
---|---|
ToPaginatedListAsync<T>() | A very simple method for pagination, it is generic which can work on your main entity or projection type. It takes page number and page size and handle the pagination calculations and returns two objects, the first one is the IEnumerable<T> with the specified number of records and meta data object with pagination data |
WhereIf<T>() | Filters a sequence of values based on a predicate with apply predicate condtion either to apply the predicate or not |
Sort<T>() | Sorts the elements of a sequence according to a key(s) and order direction, very useful when you have sort by feature. Just define a string with keys and sort direction like the following: "name desc,country,age asce" |
Enumerable Extensions:
Method | Description |
---|---|
WhereIf<T>() | Filters a sequence of values based on a predicate with apply predicate condtion either to apply the predicate or not |
HasDuplicates<T>() | Determines whether a sequence contains any duplicate elements |
FindDuplicates<T>() | Returns duplicate elements in a sequence if exist |
RemoveDuplicates<T>() | Remove duplicate elements in a sequence if exist |
CountDuplicates<T>() | Get duplicate elements with number of duplication |
TotalDuplicates<T>() | Returns a number that represents how many elements in the specified sequence are duplicated |
ForEach<T>() | Performs the specified Func delegate on each element of the sequence and return new sequence |
Enum Extensions:
Method | Description |
---|---|
GetAttribute<T>() | Direct way to retrieve any attribute data associated with enum type whether it is built in attribute as DescriptionAttribute or any custom attribute |
Generic Type Extensions:
Method | Description |
---|---|
ToJson<T>() | Converts the provided value into a string |
You can refer to the unit tests in the repo to see some basic usage for each method.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Linq.Dynamic.Core (>= 1.3.3)
- System.Text.Json (>= 7.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 195 | 7/6/2023 |
1.0.0 | 159 | 6/25/2023 |
0.0.0-alpha.0.9 | 85 | 6/25/2023 |