TechnicalUtilities 2.0.0
dotnet add package TechnicalUtilities --version 2.0.0
NuGet\Install-Package TechnicalUtilities -Version 2.0.0
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="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TechnicalUtilities --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TechnicalUtilities, 2.0.0"
#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=2.0.0 // Install TechnicalUtilities as a Cake Tool #tool nuget:?package=TechnicalUtilities&version=2.0.0
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 2.0.0
Support version: net5, net6, net7
New Feature
- Technical Excel Utilities
- CreateFile
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 |
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:
- 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
- FormatSpaceText
string text = " Hello guys ";
text.FormatSpaceText();
//Result: "Hello guys"
- ToCapitalize
string text = "HOW ARE YOU, TO DAY?";
text.ToCapitalize();
//Result: "How are you, to day?"
- ToTitleCase
string text = "how are you, to day?";
text.ToTitleCase();
//Result: "How Are You, To Day?"
- 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
- 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
- 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
- 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 |
CreateFile | string | Create new file with content |
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
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 | 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
- Aspose.Cells (>= 23.8.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 5.0.6)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- Aspose.Cells (>= 23.8.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 5.0.6)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Aspose.Cells (>= 23.8.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 5.0.6)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.