Update old xml docs

This commit is contained in:
Stone_Red
2024-03-21 08:26:35 +01:00
parent 3bd8a28304
commit e2c3e6e2af
5 changed files with 174 additions and 135 deletions
+9 -8
View File
@@ -34,11 +34,12 @@ public enum TableStyle
public static class CollectionExt
{
/// <summary>
/// Prints all items of an <see cref="IEnumerable{T}"/>
/// Prints the elements of the collection.
/// </summary>
/// <param name="collection"></param>
/// <param name="delimiter"></param>
/// <param name="printToDebugConsole"></param>
/// <typeparam name="T">The type of the elements in the collection.</typeparam>
/// <param name="collection">The collection to print.</param>
/// <param name="delimiter">The delimiter character to use between elements. Default is ','.</param>
/// <param name="printToDebugConsole">Indicates whether to print to the debug console. Default is false.</param>
public static void Print<T>(this IEnumerable<T> collection, char delimiter = ',', bool printToDebugConsole = false)
{
int i = 0;
@@ -63,11 +64,11 @@ public static class CollectionExt
}
/// <summary>
/// Creates and prints table from 2D array
/// Prints the elements of the 2D array in a table format.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <param name="tableStyle"></param>
/// <typeparam name="T">The type of the elements in the array.</typeparam>
/// <param name="array">The 2D array to print.</param>
/// <param name="tableStyle">The style of the table. Default is TableStyle.Default.</param>
public static void PrintTable<T>(this T[,] array, TableStyle tableStyle = TableStyle.Default)
{
int[] itemLength = new int[array.GetLength(1)];
+19 -20
View File
@@ -11,10 +11,10 @@ namespace CuteUtils;
public static class ConsoleExt
{
/// <summary>
/// Writes the text representation of the specified object to the standard output stream.
/// Writes the specified value to the console with the specified color.
/// </summary>
/// <param name="value"></param>
/// <param name="color"></param>
/// <param name="value">The value to write.</param>
/// <param name="color">The color of the text.</param>
public static void Write(object value, ConsoleColor color)
{
lock (Console.Out)
@@ -27,10 +27,10 @@ public static class ConsoleExt
}
/// <summary>
/// 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.
/// </summary>
/// <param name="value"></param>
/// <param name="color"></param>
/// <param name="value">The value to write.</param>
/// <param name="color">The color of the text.</param>
public static void WriteLine(object value, ConsoleColor color)
{
lock (Console.Out)
@@ -45,9 +45,9 @@ public static class ConsoleExt
/// <summary>
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type to convert the input string to.</typeparam>
/// <returns>The input string converted to the specified type.</returns>
/// <exception cref="NotSupportedException"></exception>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadLine<T>()
{
string attemptedValue = Console.ReadLine() ?? string.Empty;
@@ -60,9 +60,9 @@ public static class ConsoleExt
/// <summary>
/// Reads the next line of characters from the standard input stream and tries to convert it to the specified type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type to convert the input string to.</typeparam>
/// <param name="input">The input string converted to the specified type.</param>
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/></returns>
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/>.</returns>
public static bool TryReadLine<T>([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.
/// </summary>
/// <typeparam name="T">The type of the </typeparam>
/// <typeparam name="T">The type to convert the input character to.</typeparam>
/// <returns>The input character converted to the specified type.</returns>
/// <exception cref="NotSupportedException"></exception>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadKey<T>()
{
string attemptedValue = Console.ReadKey().KeyChar.ToString();
@@ -101,15 +101,14 @@ public static class ConsoleExt
/// The pressed key is displayed in the console window.
/// </summary>
/// <param name="input">The input character converted to the specified type.</param>
/// <typeparam name="T">The type of the </typeparam>
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/></returns>
/// <typeparam name="T">The type to convert the input character to.</typeparam>
/// <returns><see langword="true"/> if the conversion was successful. Otherwise <see langword="false"/>.</returns>
public static bool TryReadKey<T>([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
}
/// <summary>
/// Suspends execution of the current method until the user presses a key
/// Suspends execution of the current method until the user presses a key.
/// </summary>
/// <param name="key">The key that has to be pressed</param>
/// <param name="message">The message that will be displayed</param>
/// <param name="key">The key that has to be pressed.</param>
/// <param name="message">The message that will be displayed.</param>
public static void Pause(ConsoleKey key, string? message = null)
{
Console.WriteLine(message ?? $"Press {key} to continue...");
@@ -137,9 +136,9 @@ public static class ConsoleExt
}
/// <summary>
/// Suspends execution of the current method until the user presses a key
/// Suspends execution of the current method until the user presses a key.
/// </summary>
/// <param name="message">The message that will be displayed</param>
/// <param name="message">The message that will be displayed.</param>
public static void Pause(string message = "Press any key to continue...")
{
Console.WriteLine(message);
+30 -17
View File
@@ -1,22 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>CuteUtils</Title>
<Authors>Stone_Red</Authors>
<PackageProjectUrl>https://github.com/Stone-Red-Code/CuteUtils</PackageProjectUrl>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>CuteUtils</Title>
<Authors>Stone_Red</Authors>
<PackageProjectUrl>https://github.com/Stone-Red-Code/CuteUtils</PackageProjectUrl>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
<PackageReference Include="Vsxmd" Version="1.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<Deterministic>False</Deterministic>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
<PackageReference Include="Vsxmd" Version="1.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
+87 -86
View File
@@ -9,172 +9,172 @@ namespace CuteUtils.Logging;
public class Logger
{
/// <summary>
/// The logging configuration.
/// Gets or sets the log configuration.
/// </summary>
public LogConfig Config { get; init; } = new LogConfig();
/// <summary>
/// Log the message to the specified output
/// Logs a message with the specified source, log severity, and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="logSeverity"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="logSeverity">The severity level of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs a message with the specified log severity and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="logSeverity"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="logSeverity">The severity level of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs an informational message with the specified source and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs an informational message with additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
public void LogInfo(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
WriteLog(message, string.Empty, LogSeverity.Info, memberName, sourceFilePath, sourceLineNumber);
}
/// <summary>
/// Log the message to the specified output
/// Logs a warning message with the specified source and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs a warning message with additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
public void LogWarn(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
WriteLog(message, string.Empty, LogSeverity.Warn, memberName, sourceFilePath, sourceLineNumber);
}
/// <summary>
/// Log the message to the specified output
/// Logs an error message with additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
public void LogError(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
WriteLog(message, string.Empty, LogSeverity.Error, memberName, sourceFilePath, sourceLineNumber);
}
/// <summary>
/// Log the message to the specified output
/// Logs an error message with the specified source and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs a fatal error message with additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
public void LogFatal(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
WriteLog(message, string.Empty, LogSeverity.Fatal, memberName, sourceFilePath, sourceLineNumber);
}
/// <summary>
/// Log the message to the specified output
/// Logs a fatal error message with the specified source and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// Log the message to the specified output
/// Logs a debug message with additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
public void LogDebug(string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
WriteLog(message, string.Empty, LogSeverity.Debug, memberName, sourceFilePath, sourceLineNumber);
}
/// <summary>
/// Log the message to the specified output
/// Logs a debug message with the specified source and additional caller information.
/// </summary>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="condition"></param>
/// <param name="message"></param>
/// <param name="source"></param>
/// <param name="logSeverity"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="condition">The condition to check.</param>
/// <param name="message">The message to log.</param>
/// <param name="source">The source of the log message.</param>
/// <param name="logSeverity">The severity level of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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
}
/// <summary>
/// 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.
/// </summary>
/// <param name="condition"></param>
/// <param name="message"></param>
/// <param name="logSeverity"></param>
/// <param name="memberName"></param>
/// <param name="sourceFilePath"></param>
/// <param name="sourceLineNumber"></param>
/// <param name="condition">The condition to check.</param>
/// <param name="message">The message to log.</param>
/// <param name="logSeverity">The severity level of the log message.</param>
/// <param name="memberName">The name of the calling member.</param>
/// <param name="sourceFilePath">The path of the source file.</param>
/// <param name="sourceLineNumber">The line number in the source file.</param>
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
}
/// <summary>
/// Clears the log file
/// Clears the log file for the specified log severity.
/// </summary>
/// <param name="logSeverity">The severity level of the log messages to clear.</param>
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 });
}
}
}
+25
View File
@@ -5,6 +5,13 @@
/// </summary>
public static class RandomExt
{
/// <summary>
/// Returns a random item from the specified enumerable.
/// </summary>
/// <typeparam name="T">The type of the items in the enumerable.</typeparam>
/// <param name="random">The random number generator.</param>
/// <param name="enumerable">The enumerable to select a random item from.</param>
/// <returns>A random item from the enumerable.</returns>
public static T NextItem<T>(this Random random, IEnumerable<T> enumerable)
{
ArgumentNullException.ThrowIfNull(enumerable);
@@ -12,17 +19,35 @@ public static class RandomExt
return enumerable.ElementAt(random.Next(enumerable.Count()));
}
/// <summary>
/// Returns a random boolean value.
/// </summary>
/// <param name="random">The random number generator.</param>
/// <returns>A random boolean value.</returns>
public static bool NextBool(this Random random)
{
return random.Next(2) == 0;
}
/// <summary>
/// Returns a random value from the specified enum type.
/// </summary>
/// <typeparam name="T">The enum type.</typeparam>
/// <param name="random">The random number generator.</param>
/// <returns>A random value from the enum type.</returns>
public static T NextEnum<T>(this Random random) where T : struct, Enum
{
T[] values = Enum.GetValues<T>();
return values[random.Next(values.Length)];
}
/// <summary>
/// Returns a random value from the specified array of enum values.
/// </summary>
/// <typeparam name="T">The enum type.</typeparam>
/// <param name="random">The random number generator.</param>
/// <param name="values">The array of enum values.</param>
/// <returns>A random value from the array of enum values.</returns>
public static T NextEnum<T>(this Random random, T[] values) where T : struct, Enum
{
return values[random.Next(values.Length)];