Update project to .NET 10

This commit is contained in:
Stone_Red
2025-11-25 19:19:41 +01:00
parent d588b6049b
commit b136dda50b
3 changed files with 138 additions and 123 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
@@ -14,9 +14,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.8.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.0.2" />
</ItemGroup>
<ItemGroup>
+2 -2
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -29,7 +29,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
<PackageReference Include="System.Reactive.Linq" Version="6.1.0" />
</ItemGroup>
<!--
+132 -117
View File
@@ -10,138 +10,153 @@ namespace CuteUtils.Misc;
/// </summary>
public static class ConsoleExt
{
/// <summary>
/// Writes the specified value to the console with the specified color.
/// </summary>
/// <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)
extension(Console)
{
lock (Console.Out)
/// <summary>
/// Writes the specified value to the console with the specified color.
/// </summary>
/// <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)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.Write(value);
Console.ForegroundColor = oldColor;
lock (Console.Out)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.Write(value);
Console.ForegroundColor = oldColor;
}
}
}
/// <summary>
/// Writes the specified value to the console with the specified color and appends a new line.
/// </summary>
/// <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)
/// <inheritdoc cref="Write(object, ConsoleColor)"/>
public static void WriteColor(object value, ConsoleColor color)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(value);
Console.ForegroundColor = oldColor;
Write(value, color);
}
}
/// <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">The type to convert the input string to.</typeparam>
/// <returns>The input string converted to the specified type.</returns>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadLine<T>()
{
string attemptedValue = Console.ReadLine() ?? string.Empty;
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
return (T)converter.ConvertFromString(attemptedValue)!;
}
/// <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">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>
public static bool TryReadLine<T>([NotNullWhen(true)] out T? input)
{
string attemptedValue = Console.ReadLine() ?? string.Empty;
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
if (converter != null && converter.IsValid(attemptedValue))
/// <summary>
/// Writes the specified value to the console with the specified color and appends a new line.
/// </summary>
/// <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)
{
input = (T)converter.ConvertFromString(attemptedValue)!;
return true;
lock (Console.Out)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(value);
Console.ForegroundColor = oldColor;
}
}
else
/// <inheritdoc cref="WriteLine(object, ConsoleColor)"/>
public static void WriteLineColor(object value, ConsoleColor color)
{
input = default;
return false;
WriteLine(value, color);
}
}
/// <summary>
/// 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 to convert the input character to.</typeparam>
/// <returns>The input character converted to the specified type.</returns>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadKey<T>()
{
string attemptedValue = Console.ReadKey().KeyChar.ToString();
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
return (T)converter.ConvertFromString(attemptedValue)!;
}
/// <summary>
/// Obtains the next character or function key pressed by the user and tries to convert it to the specified type.
/// 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 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))
/// <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">The type to convert the input string to.</typeparam>
/// <returns>The input string converted to the specified type.</returns>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadLine<T>()
{
input = (T)converter.ConvertFromString(attemptedValue)!;
return true;
}
else
{
input = default;
return false;
}
}
string attemptedValue = Console.ReadLine() ?? string.Empty;
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
/// <summary>
/// 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>
public static void Pause(ConsoleKey key, string? message = null)
{
Console.WriteLine(message ?? $"Press {key} to continue...");
ConsoleKey? consoleKey = null;
while (consoleKey != key)
{
consoleKey = Console.ReadKey(true).Key;
return (T)converter.ConvertFromString(attemptedValue)!;
}
}
/// <summary>
/// Suspends execution of the current method until the user presses a key.
/// </summary>
/// <param name="message">The message that will be displayed.</param>
public static void Pause(string message = "Press any key to continue...")
{
Console.WriteLine(message);
_ = Console.ReadKey(true);
/// <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">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>
public static bool TryReadLine<T>([NotNullWhen(true)] out T? input)
{
string attemptedValue = Console.ReadLine() ?? string.Empty;
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
if (converter != null && converter.IsValid(attemptedValue))
{
input = (T)converter.ConvertFromString(attemptedValue)!;
return true;
}
else
{
input = default;
return false;
}
}
/// <summary>
/// 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 to convert the input character to.</typeparam>
/// <returns>The input character converted to the specified type.</returns>
/// <exception cref="NotSupportedException">Thrown if the conversion is not supported.</exception>
public static T ReadKey<T>()
{
string attemptedValue = Console.ReadKey().KeyChar.ToString();
Type type = typeof(T);
TypeConverter converter = TypeDescriptor.GetConverter(type);
return (T)converter.ConvertFromString(attemptedValue)!;
}
/// <summary>
/// Obtains the next character or function key pressed by the user and tries to convert it to the specified type.
/// 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 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;
}
else
{
input = default;
return false;
}
}
/// <summary>
/// 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>
public static void Pause(ConsoleKey key, string? message = null)
{
Console.WriteLine(message ?? $"Press {key} to continue...");
ConsoleKey? consoleKey = null;
while (consoleKey != key)
{
consoleKey = Console.ReadKey(true).Key;
}
}
/// <summary>
/// Suspends execution of the current method until the user presses a key.
/// </summary>
/// <param name="message">The message that will be displayed.</param>
public static void Pause(string message = "Press any key to continue...")
{
Console.WriteLine(message);
_ = Console.ReadKey(true);
}
}
}