-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from purkayasta/development
0.1 PR
- Loading branch information
Showing
22 changed files
with
436 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
# The-UtilityVerse | ||
# The UtilityVerse | ||
|
||
## Give it a star if you like the project. 👏 🌠 🌟 | ||
|
||
UtilityVerse is for you to do what you do best. | ||
|
||
![Nuget](https://img.shields.io/nuget/v/TheUtilityVerse) | ||
![Nuget](https://img.shields.io/nuget/dt/TheUtilityVerse?style=plastic) | ||
![Nuget](https://img.shields.io/github/repo-size/purkayasta/TheUtilityVerse?style=social) | ||
![Nuget](https://img.shields.io/github/last-commit/purkayasta/TheUtilityVerse?style=flat-square) | ||
|
||
[Nuget](https://www.nuget.org/packages/TheUtilityVerse/) | ||
|
||
Invoke this library using ```UtilityVerse``` class. | ||
|
||
## Extensions | ||
- DateOnly | ||
- DateTime | ||
- Generic | ||
- Integer | ||
- Object | ||
- String | ||
|
||
|
||
## Helpers | ||
- HttpRequest Creation. | ||
- Manual Retry Mechanism | ||
|
||
|
||
|
||
Made ❤ with C#. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
UtilityVerse.Test.Console-4.8/UtilityVerse.Test.Console-4.8.csproj
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace UtilityVerse.Contracts | ||
{ | ||
public class RetryOption | ||
{ | ||
|
||
/// <summary> | ||
/// When it will retry again. | ||
/// </summary> | ||
public TimeSpan? Delay { get; set; } = TimeSpan.FromSeconds(1); | ||
|
||
/// <summary> | ||
/// Retry Count. How many time it will try? | ||
/// </summary> | ||
public int? Count { get; set; } = 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace UtilityVerse.Extensions | ||
{ | ||
public static class DateOnlyExtensions | ||
{ | ||
/// <summary> | ||
/// This method will help to determine is the dateonly instance is in between range or not. | ||
/// </summary> | ||
/// <param name="dt"></param> | ||
/// <param name="startDate"></param> | ||
/// <param name="endDate"></param> | ||
/// <returns></returns> | ||
public static bool IsInBetween(this DateOnly? dt, DateOnly? startDate, DateOnly? endDate) | ||
{ | ||
ArgumentNullException.ThrowIfNull(dt, nameof(dt)); | ||
ArgumentNullException.ThrowIfNull(startDate, nameof(startDate)); | ||
ArgumentNullException.ThrowIfNull(endDate, nameof(endDate)); | ||
|
||
return dt.Value >= startDate && dt < endDate; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace UtilityVerse.Extensions | ||
{ | ||
public static class DateTimeExtensions | ||
{ | ||
private static DateTime _defaultDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
|
||
/// <summary> | ||
/// This method will help you determine if the target datetime is within the given range (start and end) | ||
/// </summary> | ||
/// <param name="dt"></param> | ||
/// <param name="startDateTime"></param> | ||
/// <param name="endDateTime"></param> | ||
/// <returns></returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public static bool IsInBetween(this DateTime? dt, DateTime? startDateTime, DateTime? endDateTime) | ||
{ | ||
ArgumentNullException.ThrowIfNull(dt, nameof(dt)); | ||
ArgumentNullException.ThrowIfNull(startDateTime, nameof(startDateTime)); | ||
ArgumentNullException.ThrowIfNull(endDateTime, nameof(endDateTime)); | ||
|
||
return dt >= startDateTime && dt < endDateTime; | ||
} | ||
|
||
/// <summary> | ||
/// This method will convert datetime object into unix time stamp | ||
/// </summary> | ||
/// <param name="dt"></param> | ||
/// <returns></returns> | ||
public static int ToUnixTimeStamp(this DateTime? dt) | ||
{ | ||
if (dt is null) return 0; | ||
return (int)dt.Value.Subtract(_defaultDateTime).TotalSeconds; | ||
} | ||
|
||
/// <summary> | ||
/// This method will convert any valid timestamp into a DateTime object | ||
/// </summary> | ||
/// <param name="timeStamp"></param> | ||
/// <returns></returns> | ||
/// <exception cref="ArgumentOutOfRangeException"></exception> | ||
public static DateTime ToDateTime(this int? timeStamp) | ||
{ | ||
ArgumentNullException.ThrowIfNull(timeStamp); | ||
if (timeStamp < 1) throw new ArgumentOutOfRangeException(nameof(timeStamp), "invalid value"); | ||
return _defaultDateTime.AddSeconds(timeStamp.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace UtilityVerse.Extensions | ||
{ | ||
public static class GenericExtensions | ||
{ | ||
/// <summary> | ||
/// This method will convert byte array into desired model. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="byteArr"></param> | ||
/// <returns></returns> | ||
public static T? To<T>(this byte[]? byteArr) | ||
{ | ||
ArgumentNullException.ThrowIfNull(byteArr); | ||
return JsonSerializer.Deserialize<T>(byteArr); | ||
} | ||
|
||
/// <summary> | ||
/// This method will convert poco model into byte array. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="instance"></param> | ||
/// <returns></returns> | ||
public static byte[] ToByteArray<T>(this T? instance) | ||
{ | ||
ArgumentNullException.ThrowIfNull(instance); | ||
return Encoding.UTF8.GetBytes(JsonSerializer.Serialize<T>(instance)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace UtilityVerse.Extensions | ||
{ | ||
public static class IntExtensions | ||
{ | ||
/// <summary> | ||
/// This method will help to determine that source number is in between or not. | ||
/// </summary> | ||
/// <param name="source"></param> | ||
/// <param name="min"></param> | ||
/// <param name="max"></param> | ||
/// <returns></returns> | ||
public static bool IsInBetween(this int? source, int? min, int? max) | ||
{ | ||
ArgumentNullException.ThrowIfNull(source, nameof(source)); | ||
ArgumentNullException.ThrowIfNull(min, nameof(min)); | ||
ArgumentNullException.ThrowIfNull(max, nameof(max)); | ||
|
||
return min <= source && max <= source; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.