TechnicalUtilities 1.2.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TechnicalUtilities --version 1.2.2
NuGet\Install-Package TechnicalUtilities -Version 1.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TechnicalUtilities" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TechnicalUtilities --version 1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TechnicalUtilities, 1.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TechnicalUtilities as a Cake Addin #addin nuget:?package=TechnicalUtilities&version=1.2.2 // Install TechnicalUtilities as a Cake Tool #tool nuget:?package=TechnicalUtilities&version=1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TechnicalUtilities
Technical Library By Developer Ben
Setup
dotnet add package TechnicalUtilities --version 1.2.2
*Support version: net5, net6, net7*
I - Type Convert
- Can check
object
,number
,string
, ... toobject
need convert
Methods | Return Type | Description |
---|---|---|
ToString | string | Convert a value to string with format, if value null return format with null |
ToSafetyString | string | Convert a value to string , if value is null return empty |
ToByte | byte | Convert a value to byte , if value is null or empty return 0 |
ToSByte | sbyte | Convert a value to sbyte , if value is null or empty return 0 |
ToShort | short | Convert a value to short , if value is null or empty return 0 |
ToUInt | uint | Convert a value to uint , if value is null or empty return 0 |
ToUShort | ushort | Convert a value to ushort , if value is null or empty return 0 |
ToInt | int | Convert a value to int , if value is null or empty return 0 |
ToFloat | float | Convert a value to float , if value is null or empty return 0 |
ToDouble | double | Convert a value to double , if value is null or empty return 0 |
ToLong | long | Convert a value to long , if value is null or empty return 0 |
ToULong | ulong | Convert a value to ulong , if value is null or empty return 0 |
ToDecimal | decimal | Convert a value to decimal , if value is null or empty return 0 |
ToChar | char | Convert a value to char , if value is null or empty or length of value > 1 return space |
ToBool | bool | Check a value is string or number |
ToDateTime | DateTime | Convert a value to DateTime |
ToVNDCurrency | string | Convert a value to format default unit VND |
ToNoSignFormat | string | Convert a value to string no sign |
ReverseString | string | Revert a string |
ConvertUrlsToListString | string | Convert a string value to list string with default char key is ; |
ConvertStringToListString | string | Convert a string value to list string with a char key |
ConvertListStringToString | string | Join a list string to a value string with a char key |
DatetimeToDateNotHour | DateTime | Convert a DateTime value to DateTime but hour is 00:00:00 |
CurrentTimeAgo | string | Count time from past to current |
CurrentTimeNext | string | Count time from current to DateTime value in future |
CheckOutTime | bool | Check TimeSpan has than 0 of DateTime value |
Use:
- ToString
value.ToString();
value.ToString("{0}")
- ToSafetyString
var value = null;
value.ToSafetyString();
// Result: Empty
string value = "demo example";
value.ToSafetyString();
//Result: "demo example"
- ToByte, ToSByte, ToShort, ToUInt, ToUShort, ToInt, ToFloat , ToLong, ToULong, ToDecimal
var value = null;
value.ToByte();
//Result: 0
string value = " ";
value.ToByte();
//Result: 0
- ToChar
var value = null;
value.ToChar();
//Result: " "
string value = "";
value.ToChar();
//Result: " "
string value = "example";
value.ToChar();
//Result: " "
string value = "a"
value.ToChar();
//Result: 'a'
- ToDateTime
string value = "a"
value.ToChar();
//Result: 'a'
- ToVNDCurrency
number money = 200000;
money.ToVNDCurrency();
//Result: 200,000
money.ToVNDCurrency(true);
//Result: 200,000 VND
- ToNoSignFormat
string value = " Xin Chào ";
value.ToNoSignFormat();
//Result: " xin chao ";
value.ToNoSignFormat(true);
//Result: "xin chao";
- ReverseString
string value = " example ";
value.ReverseString();
//Result: " elpmaxe ";
value.ReverseString(true);
//Result: "elpmaxe";
- ConvertStringToListString
string str = "apple, orange, tomato";
str.ConvertStringToListString(',');
//Result: ["apple", "orange", "tomato"]
- ConvertListStringToString
List<string> values = new List<string>{"apple", "orange", "tomato"};
values.ConvertListStringToString(';');
//Result: "apple;orange;tomato";
- DatetimeToDateNotHour
DateTime dt = new DateTime();
dt.DatetimeToDateNotHour();
//Result: "2023/12/22 00:00:00";
- CurrentTimeAgo (Apply for Vietnamese)
DateTime past = new DateTime(2023, 12, 22, 20, 0,0);
# example now is 2023/12/22 23:00:00
past.CurrentTimeAgo();
//Result: "3 Giờ Trước"
- CurrentTimeNext (Apply for Vietnamese)
DateTime future = new DateTime(2023, 12, 22, 23, 0,0);
# example now is 2023/12/22 20:00:00
future.CurrentTimeNext();
//Result: "Còn 3 giờ"
- CheckOutTime
DateTime past = new DateTime(2023, 12, 22, 20, 0,0);
example now is 2023/12/22 23:00:00
future.CheckOutTime();
//Result: True
II - Generate
- Generate string, guid, number, string and number ascending
Methods | Return Type | Description |
---|---|---|
RandomNumber | string | Generate to a string with length, from min number to max number |
RandomString | string | Geneate to a string with min length and max length, or has number, symboy, has uppercase |
RandomStringUpper | string | Geneeate to a string with length is UpperCase |
RandomGuid | string | Generate to a string is Guid |
GenerateNumberAscending | string | Generate to a string with start number, max number and char number need ascending |
Use
- RandomNumber
string random = TechnicalGenerateUtility.RandomNumber(3);
//Result: 123
string random = TechnicalGenerateUtility.RandomNumber(1,9);
//Result: 4
- RandomString
* Normal
string random = TechnicalGenerateUtility.RandomString(1,6);
//Result: abcjsc
* Has Number
string random = TechnicalGenerateUtility.RandomString(1,6,true);
//Result: abc123
* Has Symboy
string random = TechnicalGenerateUtility.RandomString(1,6,true, true);
//Result: abc$123
* Has UpperCase
string random = TechnicalGenerateUtility.RandomString(1,6,true, true, true);
//Result: ABC$123
- RandomStringUpper
string random = TechnicalGenerateUtility.RandomStringUpper(5)
//Result: ABCDRF
- RandomGuid
string random = TechnicalGenerateUtility.RandomGuid();
//Result: c17d172b-5829-4931-ba9f-d426bdaaa2ca
- GenerateNumberAscending
string random = TechnicalGenerateUtility.GenerateNumberAscending(1, 6);
//Result: 000002
string random = TechnicalGenerateUtility.GenerateNumberAscending(1, 6, 'Z');
//Result: ZZZZZ2
III - Security - Hash string - salt
- has a string to value need hash (
MD5
,SHA256
,SHA512
)
Methods | Return Type | Description |
---|---|---|
ToMD5 | string | return string hash with MD5 |
ToSHA256 | string | return string hash with SHA256 |
ToSHA512 | string | return string hash with SHA512 |
Use
- ToMD5
string strHashMD5 = "demo";
string result = strHashMD5.ToMD5();
//Result: 95FD23D0F1F3C610AC831F5FB8598B16
* Has Salt
string result = strHashMD5.ToMD5("salt");
//Result: E3C5E837570015A39BC0CC075E3B449D
- ToSHA256
string strHashMD5 = "demo";
string result = strHashMD5.ToSHA256();
//Result: 95FD23D0F1F3C610AC831F5FB8598B16
* Has Salt
string result = strHashMD5.ToSHA256("salt");
//Result: E3C5E837570015A39BC0CC075E3B449D
- ToSHA512
string strHashMD5 = "demo";
string result = strHashMD5.ToSHA512();
//Result: 95FD23D0F1F3C610AC831F5FB8598B16
// Has Salt
string result = strHashMD5.ToSHA512("salt");
// Result: E3C5E837570015A39BC0CC075E3B449D
IV - File
- Control with url of file
Methods | Return Type | Description |
---|---|---|
ReadFile | string | Reading a file from url |
WriteFile | string | Write content with url file |
UploadAsync | string | Upload file from IFormFile or string base 64 |
RemoveUnicode | string | Remove unicode to no sign for string |
V - Base Class Utilities
- Class base for Base Result
Methods | Return Type | Description |
---|---|---|
OperationResult |
object | Class return status success , StatusCode , Message ,Caption ,Data |
BaseResult<T> |
object | Class return one or three status SuccessResult<T> (200) , ErrorResult<T> (400) and AuthorizeResult<T> (401) with T as Class |
PaginationUtility<T> |
object | Class return TotalCount , TotalPage , PageNumber , PageSize , Skip to use in pagination data |
Use
- OperationResult
// Interface
Task<OperationResult> Demo();
// Service
Public Async Task<OperationResult> Demo()
{
return new OperationResult(){
Success = true,
StatusCode = 200,
Message = string.Empty,
Caption = "Caption",
Data = null
};
}
`Operation has constructor that:`
OperationResult(string message)
OperationResult(bool success)
OperationResult(bool success, string message)
OperationResult(bool success, string message, string caption)
OperationResult(bool success, int statusCode, string message, string caption)
- BaseResult T is class
// Class
Public class People()
{
Public int Id { get; set;}
Public string FullName { get; set;}
}
// Interface
Task<BaseResult<People>> GetPeople();
Task<BaseResult<List<People>>> GetPeoples();
// Service
Public Task<BaseResult<People>> GetPeople()
{
// return one or three
return new SuccessResult<People>(); // auto Status Code is 200
// or
return new ErrorResult<People>(); // auto Status Code is 400
// or
return new AuthorizeResult<People>(); // auto Status Code is 401
}
// SuccessResult has constructor that:
SuccessResult(string message)
SuccessResult(T result)
SuccessResult(T data, string message)
// ErrorResult has constructor that:
ErrorResult(string message)
ErrorResult(T result)
ErrorResult(T data, string message)
// AuthorizeResult has constructor that:
AuthorizeResult(string message)
- PaginationUtility T is Class
// Class
Public class People()
{
Public int Id { get; set;}
Public string FullName { get; set;}
}
// Interface
> using TechnicalUtilities;
Task<PaginationUtility<People>> GetPeoples(PaginationParam param);
// Service
> using TechnicalUtilities;
Public Task<PaginationUtility<People>> GetPeoples(PaginationParam param);
{
var listPeoples = await ......; // get data from Database
return new PaginationUtility<People>.Create(listPeoples, param.PageNumber, param.PageSize)
}
// return PaginationResult {
// TotalCount,
// TotalPage,
// PageNumber,
// PageSize,
// Skip
// }
PaginationUtility will be return object is Result is List<T> and Pagination is class PaginationResult
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
-
net6.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
-
net7.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.