TechnicalUtilities 1.2.5

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

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

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, ... 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
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
FormatSpaceText string Remove space in text
ToCapitalize string Convert text to Capital letter
ToTitleCase string Convert text with every value is uppercase in first
StringFormat string Format string with multiple value passing to format

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
  1. FormatSpaceText
string text = " Hello         guys   ";
text.FormatSpaceText();
//Result: "Hello guys"
  1. ToCapitalize
string text = "HOW ARE YOU, TO DAY?";
text.ToCapitalize();
//Result: "How are you, to day?"
  1. ToTitleCase
string text = "how are you, to day?";
text.ToTitleCase();
//Result: "How Are You, To Day?"
  1. StringFormat
string format = "hello {0}";
format.StringFormat("TOM");
//Result: "hello TOM";

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
GenerateCodeIdentity string Generate to a string with last code identity

Use

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

string random = TechnicalGenerateUtility.RandomNumber(1,9);
//Result: 4
  1. 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
  1. RandomStringUpper
string random = TechnicalGenerateUtility.RandomStringUpper(5)
//Result: ABCDRF
  1. RandomGuid
string random = TechnicalGenerateUtility.RandomGuid();
//Result: c17d172b-5829-4931-ba9f-d426bdaaa2ca
  1. GenerateNumberAscending
string random = TechnicalGenerateUtility.GenerateNumberAscending(1, 6);
//Result: 000002

string random = TechnicalGenerateUtility.GenerateNumberAscending(1, 6, 'Z');
//Result: ZZZZZ2
  1. GenerateCodeIdentity
string last = "AB00001";
string random = TechnicalGenerateUtility.GenerateCodeIdentity("AB", last.Code.Substring(2));

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
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

  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 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

VI - Technical Excel Utilities

Class Description
ExcelWookSheet WorkSheet data
ExcelWookSheet<T> WorkSheet with T is generic model data
ExcelColumn Config Column of ExcelWookSheet
ExcelCell Config Cell of ExcelWookSheet
ExcelMerge Config Merge Column and Cell of ExcelWookSheet
ExcelResult Result after render data for excel file.
ConfigDownload Worksheet Config Auto Fit Data & Save Format
ExcelBuiltInNumberFormats Excel Custom Format

1. Install

-- Add file Aspose.Total.lic to folder Resources
Folder: \\Resources\\Aspose.Total.lic
-- at Program.cs
TechnicalExcelUtilities.Install();
TechnicalExcelUtilities.Install("\\Folder\\Aspose.Total.lic");

2. Methods

Method Description
Style Create new Style Config
SetAllBorders Set Style cell has border
SetAllNoneBorders Set Style cell none border
SetAlignCenter Set Style text on cell is center
SetAlignMiddle Set Style text align middle
SetBackground Set Background Color of cell
SetBackground Set Background Color of cell
SetPictureSize Set Size of picture in cell
CompareTemplateExcel Compare Excel File Pattent with Excel File Upload
ValidateUploadData Validate value error by your config with model properties
GenerateExcelCellsFromProperties Generate List data ExcelCell with List Properties
GetValueFromDictionary Get value with property name
DownloadExcel Download Excel
DownloadExcel<T> Download Excel with generic list data

3. Example

var style = TechnicalExcelUtilities.Style();
TechnicalExcelUtilities.SetAllBorders(style);
TechnicalExcelUtilities.SetAllNoneBorders(style);
TechnicalExcelUtilities.SetAlignCenter(style);
TechnicalExcelUtilities.SetAlignMiddle(style);
TechnicalExcelUtilities.SetFontColor(style, Color.FromArgb(255, 0, 0));
TechnicalExcelUtilities.SetBackground(style, Color.FromArgb(255, 0, 0));
# Compare file upload and file template
ExcelResult result = TechnicalExcelUtilities.CompareTemplateExcel(file, "\\Folder\\Demo.xlsx");

# Model pattent
var modelProps = new List<FieldProperties>()
{
    new(0, true, ProductName , "Product name", "message error format {0} in cell {1}"),
    new(0, true, Description , "Product description", "message error format {0} in cell {1}"),
};

# Validate Error with model pattent and return data follow properties
ExcelUploadValidateData validateResult = TechnicalExcelUtilities.ValidateUploadData(productFeilds, result.WorksheetPatent, result.Worksheet);

# Worksheet to download
var worksheet = new ExcelWookSheet("result", "Error Sheet Name")
{
    Configs = new ConfigDownload(true),
    DataColumns = new List<ExcelColumn>() {
        new("I2", TechnicalExcelUtilities.ExcelBuiltInNumberFormats.Decimal_1),
        new("M2", style, true)
    }
};

# Start row to render data
int startRow = 1; 
int column = 0; 

# Value of cell to fill data
worksheet.DataCells = new List<ExcelCell>();
foreach (var model in validateResult.Result)
{
    worksheet.DataCells.AddRange(TechnicalExcelUtilities.GenerateExcelCellsFromProperties(model.Properties, startRow, column));
    startRow++;
}

# fill data to file pattent 
var resultExport = TechnicalExcelUtilities.DownloadExcel(worksheet, "\\Folder\\FilePattentDownload.xlsx");

# return result success or error
return new ErrorResult<object>(resultExport.Result, string.Empty);
return new SuccessResult<object>(resultExport.Result, string.Empty);
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.

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
2.0.0 111 9/13/2024
1.2.5 105 9/12/2024
1.2.4 138 4/16/2024
1.2.3 180 12/4/2023
1.2.2 146 9/26/2023
1.2.1 127 9/26/2023
1.2.0 123 9/26/2023
1.1.0 109 9/26/2023
1.0.0 149 9/9/2023