Update README.md

This commit is contained in:
Stone-Red-Code
2021-05-04 15:24:59 +02:00
parent a4232e98f2
commit ad540a5a39
+119 -37
View File
@@ -5,45 +5,60 @@
## Install ## Install
### Package Manager ### Package Manager
`Install-Package Stone_Red-C-Sharp-Utilities` `Install-Package Stone_Red-C-Sharp-Utilities`
### .NET CLI ### .NET CLI
`dotnet add package Stone_Red-C-Sharp-Utilities` `dotnet add package Stone_Red-C-Sharp-Utilities`
### NuGet ### NuGet
https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
<https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities>
## Namespaces ## Namespaces
### Stone_Red_Utilities.ArrListExtentions ### Stone_Red_Utilities.ArrListExtentions
#### Methods:
* Print #### Methods
* Print
* Description: Prints items of array * Description: Prints items of array
* Parameters: `this Array array`, `char delimiter`, `bool printToDebugConsole` * Parameters: `this Array array`, `char delimiter`, `bool printToDebugConsole`
* Example usage: * Example usage:
```cs ```cs
string[] yourArray = { "str1", "str2", "str3" }; string[] yourArray = { "str1", "str2", "str3" };
yourArray.Print(';'); yourArray.Print(';');
``` ```
* Output: * Output:
```
```text
str1; str2; str3 str1; str2; str3
``` ```
* Print\<T>
* Print\<T>
* Description: Prints items of list * Description: Prints items of list
* Parameters: `this List<T> list`, `char delimiter`, `bool printToDebugConsole` * Parameters: `this List<T> list`, `char delimiter`, `bool printToDebugConsole`
* Example usage: * Example usage:
```cs ```cs
List<double> yourList = new() { 1.45, 6.24, 4.14 }; List<double> yourList = new() { 1.45, 6.24, 4.14 };
yourList.Print(';'); yourList.Print(';');
``` ```
* Output: * Output:
```
```text
1.45; 6.24; 4.14 1.45; 6.24; 4.14
``` ```
* PrintTable\<T>
* PrintTable\<T>
* Description: Creates and prints table from 2D array * Description: Creates and prints table from 2D array
* Parameters: `this T[,] array`, `TableStyle tableStyle` * Parameters: `this T[,] array`, `TableStyle tableStyle`
* Example usage: * Example usage:
```cs ```cs
int[,] your2dArray = int[,] your2dArray =
{ {
@@ -53,8 +68,10 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
}; };
your2dArray.PrintTable(TableStyle.Default); your2dArray.PrintTable(TableStyle.Default);
``` ```
* Output: * Output:
```
```text
------------- -------------
| 1 | 2 | 3 | | 1 | 2 | 3 |
------------- -------------
@@ -65,38 +82,51 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
``` ```
### Stone_Red_Utilities.ConsoleExtentions ### Stone_Red_Utilities.ConsoleExtentions
#### Methods:
* Write #### Methods
* Write
* Description: Writes the text representation of the specified object to the standard output stream. * Description: Writes the text representation of the specified object to the standard output stream.
* Parameters: `object value`, `ConsoleColor color` * Parameters: `object value`, `ConsoleColor color`
* Example usage: * Example usage:
```cs ```cs
ConsoleExt.Write("text in red", ConsoleColor.Red); ConsoleExt.Write("text in red", ConsoleColor.Red);
``` ```
* Output: * Output:
```
```text
text in red text in red
``` ```
(Imagine that the text is actually red) (Imagine that the text is actually red)
* WriteLine * WriteLine
* Description: Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream. * Description: Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream.
* Parameters: `object value`, `ConsoleColor color` * Parameters: `object value`, `ConsoleColor color`
* Example usage: * Example usage:
```cs ```cs
ConsoleExt.WriteLine("text in green", ConsoleColor.Green); ConsoleExt.WriteLine("text in green", ConsoleColor.Green);
``` ```
* Output: * Output:
```
```text
text in green text in green
``` ```
(Imagine that the text is actually green) (Imagine that the text is actually green)
### Stone_Red_Utilities.BoolExtentions ### Stone_Red_Utilities.BoolExtentions
#### Methods:
* OneWayTrue #### Methods
* OneWayTrue
* Description: Sets value to true if input is true. If input is false the value will not change. * Description: Sets value to true if input is true. If input is false the value will not change.
* Parameters: `this ref bool bol`, `bool input` * Parameters: `this ref bool bol`, `bool input`
* Example usage: * Example usage:
```cs ```cs
bool bol = false; bool bol = false;
@@ -109,16 +139,20 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
bol.OneWayTrue(false); bol.OneWayTrue(false);
Console.WriteLine(bol); Console.WriteLine(bol);
``` ```
* Output: * Output:
```
```text
False False
True True
True True
``` ```
* OneWayFalse
* OneWayFalse
* Description: Sets value to false if input is false. If input is true the value will not change. * Description: Sets value to false if input is false. If input is true the value will not change.
* Parameters: `this ref bool bol`, `bool input` * Parameters: `this ref bool bol`, `bool input`
* Example usage: * Example usage:
```cs ```cs
bool bol = true; bool bol = true;
@@ -131,16 +165,20 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
bol.OneWayFalse(true); bol.OneWayFalse(true);
Console.WriteLine(bol); Console.WriteLine(bol);
``` ```
* Output: * Output:
```
```text
True True
False False
False False
``` ```
* ToInt * ToInt
* Description: Converts bool to int. * Description: Converts bool to int.
* Parameters: `this bool bol` * Parameters: `this bool bol`
* Example usage: * Example usage:
```cs ```cs
bool bol1 = false; bool bol1 = false;
bool bol2 = true; bool bol2 = true;
@@ -151,15 +189,19 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
Console.WriteLine(i); Console.WriteLine(i);
Console.WriteLine(j); Console.WriteLine(j);
``` ```
* Output: * Output:
```
```text
0 0
1 1
``` ```
* FromInt * FromInt
* Description: Converts int to bool. * Description: Converts int to bool.
* Parameters: `this ref bool bol`, `int input` * Parameters: `this ref bool bol`, `int input`
* Example usage: * Example usage:
```cs ```cs
bool bol1; bool bol1;
bool bol2; bool bol2;
@@ -170,18 +212,23 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
Console.WriteLine(bol1); Console.WriteLine(bol1);
Console.WriteLine(bol2); Console.WriteLine(bol2);
``` ```
* Output: * Output:
```
```text
false false
true true
``` ```
### Stone_Red_Utilities.StringExtentions ### Stone_Red_Utilities.StringExtentions
#### Methods #### Methods
* EqualsIgnoreCase * EqualsIgnoreCase
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case. * Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case.
* Parameters: `this string str`, `string value` * Parameters: `this string str`, `string value`
* Example usage: * Example usage:
```cs ```cs
string str1 = "BIG"; string str1 = "BIG";
string str2 = "big"; string str2 = "big";
@@ -189,15 +236,20 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
bool match = str1.EqualsIgnoreCase(str2); bool match = str1.EqualsIgnoreCase(str2);
Console.WriteLine(match); Console.WriteLine(match);
``` ```
* Output: * Output:
```
```text
True True
``` ```
* EqualsIgnoreSpaces
* EqualsIgnoreSpaces
* Description: Determines whether this instance and another specified string object have the same value regardless of spaces. * Description: Determines whether this instance and another specified string object have the same value regardless of spaces.
* Parameters: `this string str`, `string value` * Parameters: `this string str`, `string value`
* Example usage: * Example usage:
```cs ```cs
string str1 = "space"; string str1 = "space";
string str2 = " s p a c e "; string str2 = " s p a c e ";
@@ -206,14 +258,18 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
Console.WriteLine(match); Console.WriteLine(match);
``` ```
* Output: * Output:
```
```text
True True
``` ```
* EqualsIgnoreSpacesAndCase
* EqualsIgnoreSpacesAndCase
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces. * Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces.
* Parameters: `this string str`, `string value` * Parameters: `this string str`, `string value`
* Example usage: * Example usage:
```cs ```cs
string str1 = "BIG space"; string str1 = "BIG space";
string str2 = "big s p a c e "; string str2 = "big s p a c e ";
@@ -221,72 +277,98 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
bool match = str1.EqualsIgnoreSpacesAndCase(str2); bool match = str1.EqualsIgnoreSpacesAndCase(str2);
Console.WriteLine(match); Console.WriteLine(match);
``` ```
* Output: * Output:
```
```text
True True
``` ```
* ToFileName
* ToFileName
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces. * Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces.
* Parameters: `this string str`, `string value` * Parameters: `this string str`, `string value`
* Example usage: * Example usage:
```cs ```cs
string str = "*n*/ /äme"; string str = "*n*/ /äme";
string fileName = str.ToFileName(); string fileName = str.ToFileName();
Console.WriteLine(fileName); Console.WriteLine(fileName);
``` ```
* Output: * Output:
```
```text
name name
``` ```
* ToPath
* ToPath
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces. * Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces.
* Parameters: `this string str`, `string value` * Parameters: `this string str`, `string value`
* Example usage: * Example usage:
```cs ```cs
string str = "C://goöd /päth"; string str = "C://goöd /päth";
string fileName = str.ToPath(); string fileName = str.ToPath();
Console.WriteLine(fileName); Console.WriteLine(fileName);
``` ```
* Output: * Output:
```
```text
C://good/path C://good/path
``` ```
### Stone_Red_Utilities.Logging ### Stone_Red_Utilities.Logging
#### Constructor:
* Logger #### Constructor
* Initializes the logger with the default format and a file path.
* Logger
* Description: Initializes the logger with the default format and a file path.
* Parameters: `LogTarget logTarg`, `string file`, `string defaultFormat` * Parameters: `LogTarget logTarg`, `string file`, `string defaultFormat`
* Example usage: * Example usage:
```cs ```cs
Logger logger = new Logger(LogTarget.ConsoleAndFile, "events.log", "{<dateTime>:HH:mm:ss} | {<level>,-7} | {<source>,-15} | {<message>}"); Logger logger = new Logger(LogTarget.ConsoleAndFile, "events.log", "{<dateTime>:HH:mm:ss} | {<level>,-7} | {<source>,-15} | {<message>}");
``` ```
#### Methods:
* Log #### Methods
* Log
* Description: Log the message to the specified output * Description: Log the message to the specified output
* Parameters: `string message`, `string source`, `LogSeverity logSeverity` * Parameters: `string message`, `string source`, `LogSeverity logSeverity`
* Example usage: * Example usage:
```cs ```cs
logger.Log("something happend", "Update manager", LogSeverity.Error); logger.Log("something happend", "Update manager", LogSeverity.Error);
``` ```
* Output (Depends on the specified log format): * Output (Depends on the specified log format):
```
```text
19:15:14 | Error | Update manager | something happend 19:15:14 | Error | Update manager | something happend
``` ```
* LogIf * LogIf
* Description: Log the message to the specified output if the condition is met * Description: Log the message to the specified output if the condition is met
* Parameters: `bool condition`, `string message`, `string source`, `LogSeverity logSeverity` * Parameters: `bool condition`, `string message`, `string source`, `LogSeverity logSeverity`
* Example usage: * Example usage:
```cs ```cs
logger.Log(IsValid(),"something is invalid", "Update manager", LogSeverity.Error); logger.Log(IsValid(),"something is invalid", "Update manager", LogSeverity.Error);
``` ```
* Output (Depends on the specified log format): * Output (Depends on the specified log format):
```
```text
19:15:14 | Error | Update manager | something happend 19:15:14 | Error | Update manager | something happend
``` ```
* ClearLogFile * ClearLogFile
* Description: Clears the log file * Description: Clears the log file
* Example usage: * Example usage:
```cs ```cs
logger.ClearLogFile(); logger.ClearLogFile();
``` ```