![]() |
VOOZH | about |
dotnet add package PublicUtility.Extension --version 2.1.3
NuGet\Install-Package PublicUtility.Extension -Version 2.1.3
<PackageReference Include="PublicUtility.Extension" Version="2.1.3" />
<PackageVersion Include="PublicUtility.Extension" Version="2.1.3" />Directory.Packages.props
<PackageReference Include="PublicUtility.Extension" />Project file
paket add PublicUtility.Extension --version 2.1.3
#r "nuget: PublicUtility.Extension, 2.1.3"
#:package PublicUtility.Extension@2.1.3
#addin nuget:?package=PublicUtility.Extension&version=2.1.3Install as a Cake Addin
#tool nuget:?package=PublicUtility.Extension&version=2.1.3Install as a Cake Tool
A repertoire with several methods to assist in multitasking.
To install, just run the C# compiler to generate the .dll file and once the file has been generated, just add the reference to the project or use Nuget or in nuget console, use the following command:
install-Package PublicUtility.Extension
These items are equivalent to the default "Console.WriteLine" and "Console.Write" from the System namespace. However, it presents more features such as the use by extension without the need to invoke the object directly. It can be used to show the detail of objects on the console through Serealization, it can also be used to change the default color of console letters to one of the available colors.
using PublicUtility.Extension;
var anyString = "This is a long string name for custom print or println";
Extension.Print(anyString); // Common usage.
Extension.Println(anyString); // Common usage.
anyString.Print(); // use by extension
anyString.Println(); // use by extension
To apply the color it is necessary to use a syntax similar to interpolation. The "##" indicates that the console's color alternation will start, then it is necessary to inform the color that will be used, in this case we will use the Yellow color that can be represented by "C15" and opening of couchettes "[". Everything between couchetes will have its color changed. Closing the change is handled by "]##", thus forming "##C15[xxxxxxxx]##". In the example below we will have the name "ERROR" in red, "PROFILE" in DarkMagenta and the name "WINDOWS" in cyan
using PublicUtility.Extension;
var name = "PROFILE";
var system = "WINDOWS";
Extension.Println("##C13[ERROR]##: USER ##C06[{0}]## NOT FOUND IN THE SYSTEM ##c12[{1}]##", name, system);
Extension.Print($"##C13[ERROR]##: USER ##C06[{name}]## NOT FOUND IN THE SYSTEM ##c12[{system}]##");
Converters are methods for converting value types strategically and quickly during a run. Assuming that we have a return from some object that can be either in a string format or in another primitive format and we want to get its real format, we can use the appropriate extender.
using PublicUtility.Extension;
string number = "1041.31";
double convertedToDouble = number.AsDouble(); // output 1041.31
decimal convertedToDecimal = convertedToDouble.AsDecimal(); // output 1041.31m
float convertedToFloat = convertedToDecimal.AsFloat(); // output 1041.31f
int convertedToInt = convertedToFloat.AsInt(); // output 1041
Gets the safe value of a return. If the returned value cannot be converted to the specified type, the default value of the specified type will be returned, preventing the application from crashing.
using PublicUtility.Extension;
string datetimeOK = "30-08-2022";
string datetimeNOK = "30;08;2022";
var datetimeSafeValueOK = datetimeOK.GetSafeValue<DateTime>(); // output 30/08/2022 00:00:00
var datetimeSafeValueNOK = datetimeNOK.GetSafeValue<DateTime>(); // output 01/01/0001 00:00:00
The Json Serealization and Deserealization library does not yet offer support for some specific cases, however the items in this library have already been treated and now it is possible to make the conversion without errors. It is also possible to transform a DataTable into a list or array of typed objects.
using PublicUtility.Extension;
// FOR DATA TABLES
var myObjects = Extension.DeserializeTable<MyCustomObjectModel[]>(MyDataTable); // use example 1
var myObjects2 = MyDataTable.DeserializeTable<MyCustomObjectModel[]>(); // use example 2
// OTHERS
var myObject = new MyClass { Date = DateTime.Now, Name = "Lucas" };
var jsonString = myObject.JsonSerialize(); // output "{\"name\":\"Lucas\",\"date\":\"30/08/2022 21:19:32\"}"
var myObjectDeserealized = jsonString.JsonDeserialize<MyClass>(); // output new MyClass { Date = 30/08/2022 21:19:32, Name = "Lucas" }
public class MyClass {
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("date")]
public DateTime Date { get; set; }
}
Used to validate data return in an agile and simplified way to avoid the use of multi conditions.
using PublicUtility.Extension;
string any = "1";
bool isnumber = any.IsNumber(); // checks if the string has a valid and convertible number format. Output true
bool isDate = any.IsAnyDate(); // checks if the string has any date format. Output false
bool isFilled = any.IsFilled(); // checks if the object is filled in some way. Output true
bool isBool = any.IsSomeBool(); // checks if the string has some boolean format. Output true
bool isDefault = any.IsDefault(); // Checks if the value is the object's default. Output false
They are methods that perform the action of collecting information from a point, be it an array, a list, an enumerator or other types of data. It can be used to locate object indices, values, distinctions, among others.
using PublicUtility.Extension;
var list1 = new List<int>() { 1, 2, 3, 9, 7, 5 };
var indexNumber3 = list1.GetIndex(3); // get the index of an item in a list or return -1 if not found. Output 3
var indexNumber10 = list1.GetIndex(10); // get the index of an item in a list or return -1 if not found. Output -1
var nextValue = list1.GetNext(3); // get the next item in the object list. Output 9
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on PublicUtility.Extension:
| Package | Downloads |
|---|---|
|
PublicUtility.Sql
Class library with SQL manipulation facilitator in multiple database types |
This package is not used by any popular GitHub repositories.
Critical bugs fixeds