EasyExtensions 0.1.6
See the version list below for details.
dotnet add package EasyExtensions --version 0.1.6
NuGet\Install-Package EasyExtensions -Version 0.1.6
<PackageReference Include="EasyExtensions" Version="0.1.6" />
paket add EasyExtensions --version 0.1.6
#r "nuget: EasyExtensions, 0.1.6"
// Install EasyExtensions as a Cake Addin #addin nuget:?package=EasyExtensions&version=0.1.6 // Install EasyExtensions as a Cake Tool #tool nuget:?package=EasyExtensions&version=0.1.6
EasyExtensions
Ready-to-use .NET Standard library for convenient development.
Purposes
- Easy to use - just add a few lines of code to start working with the library.
- Flexible - use the library as a base for your project.
- Fast - add new features and commands in a few minutes.
- Modern - use the latest technologies and approaches.
- Secure - protect your data and users.
- Open Source - contribute to the project and make it better.
- Free - use the library for free.
- Cross-platform - run the library on any platform.
- Lightweight - use only necessary features.
- Documented - read the documentation and start using the library.
Getting Started
Start by importing the library into your project
dotnet add package EasyExtensions --version 0.1.3
Extensions
Byte Array Extensions
/// <summary>
/// Calculate SHA512 hash of byte array.
/// </summary>
/// <param name="bytes"> Data to calculate hash. </param>
/// <returns> SHA512 hash of byte array. </returns>
string SHA512(this byte[] bytes);
Claims Principal Extensions
/// <summary>
/// Get user id.
/// </summary>
/// <param name="user"> User instance. </param>
/// <returns> User id. </returns>
/// <exception cref="KeyNotFoundException"> Throws when claim not found. </exception>
int GetId(this ClaimsPrincipal? user);
/// <summary>
/// Try get user id.
/// </summary>
/// <param name="user"> User instance. </param>
/// <returns> User id, or 0 if not found. </returns>
int TryGetId(this ClaimsPrincipal? user);
/// <summary>
/// Get user roles.
/// </summary>
/// <param name="user"> User instance. </param>
/// <param name="rolePrefix"> Role prefix, for example: "user-group-" prefix returns group like "user-group-admins" </param>
/// <returns> User roles. </returns>
IEnumerable<string> GetRoles(this ClaimsPrincipal user, string rolePrefix = "");
DateTime Extensions
/// <summary>
/// Remove microseconds from <see cref="DateTime"/>.
/// </summary>
/// <returns> DateTime without microseconds. </returns>
DateTime DropMicroseconds(this DateTime value);
/// <summary>
/// Remove microseconds from <see cref="DateTime"/>.
/// </summary>
/// <returns> DateTime without microseconds. </returns>
DateTimeOffset DropMicroseconds(this DateTimeOffset value);
/// <summary>
/// Create new datetime with same values but <see cref="DateTimeKind.Utc"/>.
/// </summary>
/// <returns> New datetime. </returns>
DateTime ToUniversalTimeWithoutOffset(this DateTime value);
/// <summary>
/// Convert datetime value to nullable datetime type.
/// </summary>
/// <returns> Wrapped datetime value. </returns>
DateTime? ToNullable(this DateTime value);
Exception Extensions
/// <summary>
/// Create string with error message from all inner exceptions if exists.
/// </summary>
/// <returns> Error message. </returns>
string ToStringWithInner(this Exception exception);
HttpRequest Extensions
/// <summary>
/// Get remote host IP address using proxy "X-Real-IP", "CF-Connecting-IP", "X-Forwarded-For" headers, or connection remote IP address.
/// </summary>
/// <returns> IP address, or "Unknown" by default. </returns>
string GetRemoteAddress(this HttpRequest request);
Math Extensions
/// <summary>
/// Pow specified foundation to exponent.
/// </summary>
/// <param name="number"> Foundation. </param>
/// <param name="exponent"> Exponent of pow. </param>
/// <returns> Calculation result. </returns>
/// <exception cref="OverflowException"> Throws when calculation result is too big. </exception>
int Pow(this int number, int exponent);
Object Extensions
/// <summary>
/// Clone object with MemberwiseClone.
/// </summary>
/// <typeparam name="TObj"> Type of object. </typeparam>
/// <param name="obj"> Object to clone. </param>
/// <returns> Cloned object. </returns>
TObj MemberwiseClone<TObj>(this TObj obj);
ServiceCollection Extensions
/// <summary>
/// Adds <see cref="CpuUsageService"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"> Current <see cref="IServiceCollection"/> instance. </param>
/// <returns> Current <see cref="IServiceCollection"/> instance. </returns>
IServiceCollection AddCpuUsageService(this IServiceCollection services);
/// <summary>
/// Add all types inherited from TInterface.
/// </summary>
/// <param name="services"> Current <see cref="IServiceCollection"/> instance. </param>
/// <param name="serviceLifetime"> Service lifetime, default is Scoped. </param>
/// <typeparam name="TInterface"> Interface type. </typeparam>
/// <returns> Current <see cref="IServiceCollection"/> instance. </returns>
IServiceCollection AddTypesOfInterface<TInterface>(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped) where TInterface : class
Stream Extensions
/// <summary>
/// Reads the bytes from the current stream and writes them to the byte array.
/// </summary>
/// <returns> Received byte array. </returns>
/// <exception cref="IOException"> An I/O error occurred. </exception>
/// <exception cref="ArgumentNullException"> Destination is null. </exception>
/// <exception cref="ObjectDisposedException"> Either the current stream or the destination stream is disposed. </exception>
/// <exception cref="NotSupportedException"> The current stream does not support reading, or the destination stream does not support writing. </exception>
byte[] ReadToEnd(this Stream stream);
/// <summary>
/// Asynchronously reads the bytes from the current stream and writes them to the byte array.
/// </summary>
/// <returns> Received byte array. </returns>
/// <exception cref="ArgumentNullException"> Destination is null. </exception>
/// <exception cref="ObjectDisposedException"> Either the current stream or the destination stream is disposed. </exception>
/// <exception cref="NotSupportedException"> The current stream does not support reading, or the destination stream does not support writing. </exception>
public static async Task<byte[]> ReadToEndAsync(this Stream stream)
/// <summary>
/// Calculate SHA512 hash of byte stream.
/// </summary>
/// <param name="stream"> Data to calculate hash. </param>
/// <returns> SHA512 hash of byte stream. </returns>
string SHA512(this Stream stream);
String Extensions
/// <summary>
/// Make first letter as lower case. If text is null or whitespace - returns <see cref="string.Empty"/>
/// </summary>
/// <returns> Text with lower case first letter. </returns>
string ToLowerFirstLetter(this string text);
/// <summary>
/// Make first letter as upper case. If text is null or whitespace - returns <see cref="string.Empty"/>
/// </summary>
/// <returns> Text with upper case first letter. </returns>
string ToUpperFirstLetter(this string text);
/// <summary>
/// Create SHA512 hash of specified text string.
/// </summary>
/// <returns> SHA512 hash. </returns>
string SHA512(this string str);
/// <summary>
/// Read only numbers from specified string.
/// </summary>
/// <returns> Parsed number, or -1 by default. </returns>
long ReadOnlyNumbers(this string str);
Helpers
DateTime Helpers
/// <summary>
/// Parse DateTime from JSON format ISO 8601.
/// </summary>
/// <returns> Parsed datetime with UTC kind. </returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="FormatException"></exception>
/// <exception cref="NotSupportedException"></exception>
DateTime ParseDateTime(string datetime);
/// <summary>
/// Parse DateTimeOffset from JSON format ISO 8601.
/// </summary>
/// <returns> Parsed datetime offset. </returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="FormatException"></exception>
DateTimeOffset ParseDateTimeOffset(string datetime);
Reflection Helpers
/// <summary>
/// Get all types inherited from interface.
/// </summary>
/// <typeparam name="TInterface"> Interface type. </typeparam>
/// <returns> All types inherited from interface. </returns>
IEnumerable<Type> GetTypesOfInterface<TInterface>() where TInterface : class
String Helpers
/// <summary>
/// Fast generate pseudo random string with <see cref="DefaultCharset"/> and string length.
/// </summary>
/// <returns> Pseudo-random string. </returns>
string CreatePseudoRandomString();
/// <summary>
/// Fast generate pseudo random string with <see cref="DefaultCharset"/> and specified string length.
/// </summary>
/// <param name="length"> Result string length. </param>
/// <returns> Pseudo-random string. </returns>
string CreatePseudoRandomString(int length);
/// <summary>
/// Fast generate pseudo random string with specified charset and string length.
/// </summary>
/// <param name="charset"> Generator charset. </param>
/// <param name="length"> Result string length. </param>
/// <returns> Pseudo-random string. </returns>
string CreatePseudoRandomString(int length, string charset);
/// <summary>
/// Generate random string with <see cref="DefaultCharset"/> and string length.
/// </summary>
/// <returns> Really random string. </returns>
string CreateRandomString();
/// <summary>
/// Generate random string with <see cref="DefaultCharset"/> and specified string length.
/// </summary>
/// <param name="length"> Result string length. </param>
/// <returns> Really random string. </returns>
string CreateRandomString(int length);
/// <summary>
/// Generate random string with specified charset and string length.
/// </summary>
/// <param name="charset"> Generator charset. </param>
/// <param name="length"> Result string length. </param>
/// <returns> Really random string. </returns>
string CreateRandomString(int length, string charset);
Quartz Extensions
ServiceCollection Extensions
/// <summary>
/// Adds Quartz jobs with <see cref="JobTriggerAttribute"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services">IServiceCollection instance.</param>
/// <returns> Current <see cref="IServiceCollection"/> instance. </returns>
IServiceCollection AddQuartzJobs(this IServiceCollection services);
example of usage:
builder.Services.AddQuartzJobs();
Attributes
JobTriggerAttribute
Example of usage:
[JobTrigger(minutes: 1)]
[DisallowConcurrentExecution]
public class TestJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Test job executed.");
return Task.CompletedTask;
}
}
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
<p align="right"><a href="#readme-top">back to top</a></p>
License
Distributed under the MIT License. See LICENSE.md for more information.
Contact
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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on EasyExtensions:
Package | Downloads |
---|---|
EasyExtensions.AspNetCore
Ready-to-use library for simplifying the development of .NET applications. |
|
EasyExtensions.Quartz
Ready-to-use library for simplifying the development of .NET applications. |
|
EasyExtensions.EntityFrameworkCore
Ready-to-use library for simplifying the development of .NET applications. |
|
EasyExtensions.Drawing
Ready-to-use library for simplifying the development of .NET applications. |
|
EasyExtensions.AspNetCore.Authorization
Ready-to-use library for simplifying the development of .NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.84 | 303 | 11/19/2024 |
0.1.83 | 268 | 11/15/2024 |
0.1.82 | 130 | 11/15/2024 |
0.1.81 | 183 | 11/13/2024 |
0.1.80 | 332 | 11/10/2024 |
0.1.79 | 495 | 10/22/2024 |
0.1.78 | 156 | 10/21/2024 |
0.1.77 | 161 | 10/21/2024 |
0.1.76 | 121 | 10/21/2024 |
0.1.75 | 122 | 10/21/2024 |
0.1.74 | 113 | 10/21/2024 |
0.1.73 | 372 | 10/17/2024 |
0.1.72 | 240 | 10/16/2024 |
0.1.71 | 114 | 10/15/2024 |
0.1.70 | 218 | 10/15/2024 |
0.1.69 | 120 | 10/15/2024 |
0.1.68 | 212 | 10/15/2024 |
0.1.67 | 120 | 10/15/2024 |
0.1.66 | 206 | 10/14/2024 |
0.1.65 | 147 | 10/13/2024 |
0.1.64 | 121 | 10/13/2024 |
0.1.63 | 144 | 10/12/2024 |
0.1.62 | 156 | 10/12/2024 |
0.1.61 | 125 | 10/12/2024 |
0.1.60 | 193 | 10/12/2024 |
0.1.59 | 118 | 10/12/2024 |
0.1.58 | 183 | 10/11/2024 |
0.1.57 | 519 | 9/30/2024 |
0.1.56 | 122 | 9/30/2024 |
0.1.55 | 130 | 9/27/2024 |
0.1.54 | 147 | 9/27/2024 |
0.1.53 | 129 | 9/27/2024 |
0.1.52 | 156 | 9/24/2024 |
0.1.51 | 127 | 9/24/2024 |
0.1.50 | 189 | 9/24/2024 |
0.1.49 | 274 | 9/18/2024 |
0.1.48 | 178 | 9/17/2024 |
0.1.47 | 185 | 9/15/2024 |
0.1.46 | 273 | 8/22/2024 |
0.1.45 | 394 | 8/9/2024 |
0.1.44 | 153 | 8/7/2024 |
0.1.43 | 132 | 8/7/2024 |
0.1.42 | 143 | 8/7/2024 |
0.1.41 | 327 | 8/5/2024 |
0.1.40 | 152 | 8/5/2024 |
0.1.39 | 125 | 8/5/2024 |
0.1.38 | 123 | 8/5/2024 |
0.1.37 | 167 | 8/4/2024 |
0.1.36 | 125 | 8/3/2024 |
0.1.35 | 142 | 8/2/2024 |
0.1.34 | 141 | 8/2/2024 |
0.1.33 | 228 | 8/1/2024 |
0.1.32 | 128 | 8/1/2024 |
0.1.31 | 114 | 8/1/2024 |
0.1.30 | 116 | 8/1/2024 |
0.1.29 | 112 | 8/1/2024 |
0.1.28 | 155 | 8/1/2024 |
0.1.27 | 148 | 7/30/2024 |
0.1.26 | 110 | 7/30/2024 |
0.1.25 | 138 | 7/28/2024 |
0.1.24 | 116 | 7/27/2024 |
0.1.23 | 123 | 7/27/2024 |
0.1.22 | 174 | 7/27/2024 |
0.1.21 | 117 | 7/27/2024 |
0.1.20 | 121 | 7/27/2024 |
0.1.19 | 124 | 7/27/2024 |
0.1.18 | 143 | 7/26/2024 |
0.1.17 | 114 | 7/26/2024 |
0.1.16 | 143 | 7/26/2024 |
0.1.15 | 101 | 7/26/2024 |
0.1.14 | 98 | 7/26/2024 |
0.1.13 | 87 | 7/26/2024 |
0.1.12 | 92 | 7/26/2024 |
0.1.11 | 114 | 7/26/2024 |
0.1.10 | 90 | 7/26/2024 |
0.1.9 | 84 | 7/26/2024 |
0.1.8 | 82 | 7/26/2024 |
0.1.7 | 72 | 7/26/2024 |
0.1.6 | 67 | 7/26/2024 |
0.1.5 | 88 | 7/26/2024 |
0.1.4 | 49 | 7/26/2024 |
0.1.3 | 71 | 7/24/2024 |
0.1.2 | 67 | 7/23/2024 |
0.1.1 | 57 | 7/23/2024 |
0.1.0 | 55 | 7/23/2024 |