From e2c3e6e2af1907cc94b9481f024fd23f131b5531 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 21 Mar 2024 08:19:20 +0100 Subject: [PATCH] Update old xml docs --- src/CuteUtils/CollectionExtentions.cs | 19 +-- src/CuteUtils/ConsoleExtentions.cs | 41 +++--- src/CuteUtils/CuteUtils.csproj | 47 ++++--- src/CuteUtils/Logging/Logger.cs | 175 +++++++++++++------------- src/CuteUtils/RandomExtentions.cs | 27 +++- 5 files changed, 174 insertions(+), 135 deletions(-) diff --git a/src/CuteUtils/CollectionExtentions.cs b/src/CuteUtils/CollectionExtentions.cs index a9dcb84..a9cb784 100644 --- a/src/CuteUtils/CollectionExtentions.cs +++ b/src/CuteUtils/CollectionExtentions.cs @@ -34,11 +34,12 @@ public enum TableStyle public static class CollectionExt { /// - /// Prints all items of an + /// Prints the elements of the collection. /// - /// - /// - /// + /// The type of the elements in the collection. + /// The collection to print. + /// The delimiter character to use between elements. Default is ','. + /// Indicates whether to print to the debug console. Default is false. public static void Print(this IEnumerable collection, char delimiter = ',', bool printToDebugConsole = false) { int i = 0; @@ -63,11 +64,11 @@ public static class CollectionExt } /// - /// Creates and prints table from 2D array + /// Prints the elements of the 2D array in a table format. /// - /// - /// - /// + /// The type of the elements in the array. + /// The 2D array to print. + /// The style of the table. Default is TableStyle.Default. public static void PrintTable(this T[,] array, TableStyle tableStyle = TableStyle.Default) { int[] itemLength = new int[array.GetLength(1)]; @@ -126,4 +127,4 @@ public static class CollectionExt } Console.WriteLine(); } -} \ No newline at end of file +} diff --git a/src/CuteUtils/ConsoleExtentions.cs b/src/CuteUtils/ConsoleExtentions.cs index 347a30d..5ca80d1 100644 --- a/src/CuteUtils/ConsoleExtentions.cs +++ b/src/CuteUtils/ConsoleExtentions.cs @@ -11,10 +11,10 @@ namespace CuteUtils; public static class ConsoleExt { /// - /// Writes the text representation of the specified object to the standard output stream. + /// Writes the specified value to the console with the specified color. /// - /// - /// + /// The value to write. + /// The color of the text. public static void Write(object value, ConsoleColor color) { lock (Console.Out) @@ -27,10 +27,10 @@ public static class ConsoleExt } /// - /// Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream. + /// Writes the specified value to the console with the specified color and appends a new line. /// - /// - /// + /// The value to write. + /// The color of the text. public static void WriteLine(object value, ConsoleColor color) { lock (Console.Out) @@ -45,9 +45,9 @@ public static class ConsoleExt /// /// Reads the next line of characters from the standard input stream and tries to convert it to the specified type. /// - /// + /// The type to convert the input string to. /// The input string converted to the specified type. - /// + /// Thrown if the conversion is not supported. public static T ReadLine() { string attemptedValue = Console.ReadLine() ?? string.Empty; @@ -60,9 +60,9 @@ public static class ConsoleExt /// /// Reads the next line of characters from the standard input stream and tries to convert it to the specified type. /// - /// + /// The type to convert the input string to. /// The input string converted to the specified type. - /// if the conversion was successful. Otherwise + /// if the conversion was successful. Otherwise . public static bool TryReadLine([NotNullWhen(true)] out T? input) { string attemptedValue = Console.ReadLine() ?? string.Empty; @@ -84,9 +84,9 @@ public static class ConsoleExt /// Obtains the next character or function key pressed by the user and converts it to the specified type. /// The pressed key is displayed in the console window. /// - /// The type of the + /// The type to convert the input character to. /// The input character converted to the specified type. - /// + /// Thrown if the conversion is not supported. public static T ReadKey() { string attemptedValue = Console.ReadKey().KeyChar.ToString(); @@ -101,15 +101,14 @@ public static class ConsoleExt /// The pressed key is displayed in the console window. /// /// The input character converted to the specified type. - /// The type of the - /// if the conversion was successful. Otherwise + /// The type to convert the input character to. + /// if the conversion was successful. Otherwise . public static bool TryReadKey([NotNullWhen(true)] out T? input) { string attemptedValue = Console.ReadKey().KeyChar.ToString(); Type type = typeof(T); TypeConverter converter = TypeDescriptor.GetConverter(type); if (converter != null && converter.IsValid(attemptedValue)) - { input = (T)converter.ConvertFromString(attemptedValue)!; return true; @@ -122,10 +121,10 @@ public static class ConsoleExt } /// - /// Suspends execution of the current method until the user presses a key + /// Suspends execution of the current method until the user presses a key. /// - /// The key that has to be pressed - /// The message that will be displayed + /// The key that has to be pressed. + /// The message that will be displayed. public static void Pause(ConsoleKey key, string? message = null) { Console.WriteLine(message ?? $"Press {key} to continue..."); @@ -137,12 +136,12 @@ public static class ConsoleExt } /// - /// Suspends execution of the current method until the user presses a key + /// Suspends execution of the current method until the user presses a key. /// - /// The message that will be displayed + /// The message that will be displayed. public static void Pause(string message = "Press any key to continue...") { Console.WriteLine(message); _ = Console.ReadKey(true); } -} \ No newline at end of file +} diff --git a/src/CuteUtils/CuteUtils.csproj b/src/CuteUtils/CuteUtils.csproj index 30470d5..804a56e 100644 --- a/src/CuteUtils/CuteUtils.csproj +++ b/src/CuteUtils/CuteUtils.csproj @@ -1,22 +1,35 @@  - - net8.0 - enable - enable - True - CuteUtils - Stone_Red - https://github.com/Stone-Red-Code/CuteUtils - True - + + net8.0 + enable + enable + True + CuteUtils + Stone_Red + https://github.com/Stone-Red-Code/CuteUtils + True + README.md + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + False + False + + + + + True + \ + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/src/CuteUtils/Logging/Logger.cs b/src/CuteUtils/Logging/Logger.cs index 73f13b3..ce43d68 100644 --- a/src/CuteUtils/Logging/Logger.cs +++ b/src/CuteUtils/Logging/Logger.cs @@ -9,172 +9,172 @@ namespace CuteUtils.Logging; public class Logger { /// - /// The logging configuration. + /// Gets or sets the log configuration. /// public LogConfig Config { get; init; } = new LogConfig(); /// - /// Log the message to the specified output + /// Logs a message with the specified source, log severity, and additional caller information. /// - /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The severity level of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void Log(string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, logSeverity, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a message with the specified log severity and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The severity level of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void Log(string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, logSeverity, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs an informational message with the specified source and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogInfo(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs an informational message with additional caller information. /// - /// - /// - /// - /// + /// The message to log. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogInfo(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a warning message with the specified source and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogWarn(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a warning message with additional caller information. /// - /// - /// - /// - /// + /// The message to log. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogWarn(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs an error message with additional caller information. /// - /// - /// - /// - /// + /// The message to log. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogError(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs an error message with the specified source and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogError(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a fatal error message with additional caller information. /// - /// - /// - /// - /// + /// The message to log. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogFatal(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a fatal error message with the specified source and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogFatal(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a debug message with additional caller information. /// - /// - /// - /// - /// + /// The message to log. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogDebug(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, string.Empty, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output + /// Logs a debug message with the specified source and additional caller information. /// - /// - /// - /// - /// - /// + /// The message to log. + /// The source of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogDebug(string message, string source, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { WriteLog(message, source, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber); } /// - /// Log the message to the specified output if the condition is met + /// Logs a message with the specified source, log severity, and additional caller information if the condition is met. /// - /// - /// - /// - /// - /// - /// - /// + /// The condition to check. + /// The message to log. + /// The source of the log message. + /// The severity level of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogIf(bool condition, string message, string source, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { if (condition) @@ -184,14 +184,14 @@ public class Logger } /// - /// Log the message to the specified output if the condition is met + /// Logs a message with the specified log severity and additional caller information if the condition is met. /// - /// - /// - /// - /// - /// - /// + /// The condition to check. + /// The message to log. + /// The severity level of the log message. + /// The name of the calling member. + /// The path of the source file. + /// The line number in the source file. public void LogIf(bool condition, string message, LogSeverity logSeverity, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { if (condition) @@ -201,8 +201,9 @@ public class Logger } /// - /// Clears the log file + /// Clears the log file for the specified log severity. /// + /// The severity level of the log messages to clear. public void ClearLogFile(LogSeverity logSeverity) { OutputConfig outputConfig = GetOutputConfig(logSeverity); @@ -257,7 +258,7 @@ public class Logger File.Create(outputConfig.FilePath).Close(); } - File.AppendAllLines(outputConfig.FilePath, [fileOutput]); + File.AppendAllLines(outputConfig.FilePath, new[] { fileOutput }); } } } @@ -273,4 +274,4 @@ public class Logger _ => Config.DebugConfig }; } -} \ No newline at end of file +} diff --git a/src/CuteUtils/RandomExtentions.cs b/src/CuteUtils/RandomExtentions.cs index c8922a6..36fc0d8 100644 --- a/src/CuteUtils/RandomExtentions.cs +++ b/src/CuteUtils/RandomExtentions.cs @@ -5,6 +5,13 @@ /// public static class RandomExt { + /// + /// Returns a random item from the specified enumerable. + /// + /// The type of the items in the enumerable. + /// The random number generator. + /// The enumerable to select a random item from. + /// A random item from the enumerable. public static T NextItem(this Random random, IEnumerable enumerable) { ArgumentNullException.ThrowIfNull(enumerable); @@ -12,19 +19,37 @@ public static class RandomExt return enumerable.ElementAt(random.Next(enumerable.Count())); } + /// + /// Returns a random boolean value. + /// + /// The random number generator. + /// A random boolean value. public static bool NextBool(this Random random) { return random.Next(2) == 0; } + /// + /// Returns a random value from the specified enum type. + /// + /// The enum type. + /// The random number generator. + /// A random value from the enum type. public static T NextEnum(this Random random) where T : struct, Enum { T[] values = Enum.GetValues(); return values[random.Next(values.Length)]; } + /// + /// Returns a random value from the specified array of enum values. + /// + /// The enum type. + /// The random number generator. + /// The array of enum values. + /// A random value from the array of enum values. public static T NextEnum(this Random random, T[] values) where T : struct, Enum { return values[random.Next(values.Length)]; } -} \ No newline at end of file +}