Obsolete the AnsiConsoleFactory class (#585)

`AnsiConsoleFactory` should be an internal static class. Creating an `IAnsiConsole` can be achieved through `Spectre.Console.AnsiConsole.Create(AnsiConsoleSettings)`

Since `AnsiConsoleFactory` is public, it can't be changed from a non static class to a static class so obsoleting it is the second best thing to do.

Eventually, when `AnsiConsoleFactory` becomes internal and static, `AnsiConsole.Create` can be simplified to this (and the private static field `_factory` can be removed)

```
public static IAnsiConsole Create(AnsiConsoleSettings settings)
{
    return AnsiConsoleFactory.Create(settings);
}
```
This commit is contained in:
Cédric Luthi 2022-03-22 22:36:04 +01:00 committed by GitHub
parent 1d8154f9b0
commit 7998ece6b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -56,8 +56,7 @@ public sealed class TestConsole : IAnsiConsole, IDisposable
Input = new TestConsoleInput();
EmitAnsiSequences = false;
var factory = new AnsiConsoleFactory();
_console = factory.Create(new AnsiConsoleSettings
_console = AnsiConsole.Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.Yes,
ColorSystem = (ColorSystemSupport)ColorSystem.TrueColor,

View File

@ -5,6 +5,10 @@ namespace Spectre.Console;
/// </summary>
public static partial class AnsiConsole
{
#pragma warning disable CS0618 // 'AnsiConsoleFactory' is obsolete
private static readonly AnsiConsoleFactory _factory = new AnsiConsoleFactory();
#pragma warning restore CS0618
private static Recorder? _recorder;
private static Lazy<IAnsiConsole> _console = new Lazy<IAnsiConsole>(
() =>
@ -61,8 +65,7 @@ public static partial class AnsiConsole
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
public static IAnsiConsole Create(AnsiConsoleSettings settings)
{
var factory = new AnsiConsoleFactory();
return factory.Create(settings);
return _factory.Create(settings);
}
/// <summary>

View File

@ -3,6 +3,7 @@ namespace Spectre.Console;
/// <summary>
/// Factory for creating an ANSI console.
/// </summary>
[Obsolete("Consider using AnsiConsole.Create instead.")]
public sealed class AnsiConsoleFactory
{
/// <summary>