TechnicalUtilities 1.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TechnicalUtilities --version 1.2.1
NuGet\Install-Package TechnicalUtilities -Version 1.2.1
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.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TechnicalUtilities --version 1.2.1
#r "nuget: TechnicalUtilities, 1.2.1"
#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.1

// Install TechnicalUtilities as a Cake Tool
#tool nuget:?package=TechnicalUtilities&version=1.2.1

TechnicalUtilities

Technical Library By Developer Ben

Setup

dotnet add package TechnicalUtilities --version 1.2.1

*Support version: net5, net6, net7*

I - Type Convert

  • Can check object, number, string, ... to object 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
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:

  1. ToString
value.ToString();
value.ToString("{0}")
  1. ToSafetyString
var value = null;
value.ToSafetyString();
// Result: Empty

string value = "demo example";
value.ToSafetyString();
//Result: "demo example"
  1. ToByte, ToSByte, ToShort, ToUInt, ToUShort, ToInt, ToFloat , ToLong, ToULong, ToDecimal
var value = null;
value.ToByte();
//Result: 0

string value = " ";
value.ToByte();
//Result: 0
  1. 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'
  1. ToDateTime
string value = "a"
value.ToChar();
//Result:  'a'
  1. ToVNDCurrency
number money = 200000;
money.ToVNDCurrency();
//Result: 200,000

money.ToVNDCurrency(true);
//Result: 200,000 VND
  1. ToNoSignFormat
string value = " Xin Chào ";
value.ToNoSignFormat();
//Result: " xin chao ";

value.ToNoSignFormat(true);
//Result: "xin chao";
  1. ReverseString
string value = " example ";
value.ReverseString();
//Result: " elpmaxe ";

value.ReverseString(true);
//Result: "elpmaxe";
  1. ConvertStringToListString
string str = "apple, orange, tomato";
str.ConvertStringToListString(',');
//Result: ["apple", "orange", "tomato"]
  1. ConvertListStringToString
List<string> values = new List<string>{"apple", "orange", "tomato"};
values.ConvertListStringToString(';');
//Result: "apple;orange;tomato";
  1. DatetimeToDateNotHour
DateTime dt = new DateTime();
dt.DatetimeToDateNotHour();
//Result: "2023/12/22 00:00:00";
  1. 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"

  1. 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ờ"
  1. 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

  1. RandomNumber
string random = RandomNumber(3);
//Result: 123

string random = RandomNumber(1,9);
//Result: 4
  1. RandomString
* Normal
string random = RandomString(1,6);
//Result: abcjsc

* Has Number
string random = RandomString(1,6,true);
//Result: abc123

* Has Symboy
string random = RandomString(1,6,true, true);
//Result: abc$123

* Has UpperCase
string random = RandomString(1,6,true, true, true);
//Result: ABC$123
  1. RandomStringUpper
string random = RandomStringUpper(5)
//Result: ABCDRF
  1. RandomGuid
string random = RandomGuid();
//Result: c17d172b-5829-4931-ba9f-d426bdaaa2ca
  1. GenerateNumberAscending
string random = GenerateNumberAscending(1, 6);
//Result: 000002

string random = 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

  1. ToMD5
string strHashMD5 = "demo";
string result = strHashMD5.ToMD5();
//Result: 95FD23D0F1F3C610AC831F5FB8598B16

* Has Salt
string result = strHashMD5.ToMD5("salt");
//Result: E3C5E837570015A39BC0CC075E3B449D
  1. ToSHA256
string strHashMD5 = "demo";
string result = strHashMD5.ToSHA256();
//Result: 95FD23D0F1F3C610AC831F5FB8598B16

* Has Salt
string result = strHashMD5.ToSHA256("salt");
//Result: E3C5E837570015A39BC0CC075E3B449D
  1. 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

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

  1. 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)
  1. 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)
  1. PaginationUtility T is Class
// Class 
Public class People()
{
    Public int Id { get; set;}
    Public string FullName { get; set;}
}

// Interface 
> using TechnicalBaseUtility;

Task<PaginationUtility<People>> GetPeoples(PaginationParam param);

// Service
> using TechnicalBaseUtility;
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 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

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

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.2.4 97 4/16/2024
1.2.3 149 12/4/2023
1.2.2 116 9/26/2023
1.2.1 97 9/26/2023
1.2.0 98 9/26/2023
1.1.0 83 9/26/2023
1.0.0 123 9/9/2023