Use CSharpier

This commit is contained in:
Tyrrrz
2023-08-22 21:20:04 +03:00
parent a4726fcefd
commit 21b601da66
99 changed files with 975 additions and 1163 deletions

View File

@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup>

View File

@@ -49,21 +49,23 @@ public partial class BookAddCommand
{
private static readonly Random Random = new();
private static DateTimeOffset CreateRandomDate() => new(
Random.Next(1800, 2020),
Random.Next(1, 12),
Random.Next(1, 28),
Random.Next(1, 23),
Random.Next(1, 59),
Random.Next(1, 59),
TimeSpan.Zero
);
private static DateTimeOffset CreateRandomDate() =>
new(
Random.Next(1800, 2020),
Random.Next(1, 12),
Random.Next(1, 28),
Random.Next(1, 23),
Random.Next(1, 59),
Random.Next(1, 59),
TimeSpan.Zero
);
private static Isbn CreateRandomIsbn() => new(
Random.Next(0, 999),
Random.Next(0, 99),
Random.Next(0, 99999),
Random.Next(0, 99),
Random.Next(0, 9)
);
}
private static Isbn CreateRandomIsbn() =>
new(
Random.Next(0, 999),
Random.Next(0, 99),
Random.Next(0, 99999),
Random.Next(0, 99),
Random.Next(0, 9)
);
}

View File

@@ -31,4 +31,4 @@ public class BookCommand : ICommand
return default;
}
}
}

View File

@@ -33,4 +33,4 @@ public class BookListCommand : ICommand
return default;
}
}
}

View File

@@ -32,4 +32,4 @@ public class BookRemoveCommand : ICommand
return default;
}
}
}

View File

@@ -2,4 +2,4 @@
namespace CliFx.Demo.Domain;
public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn);
public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn);

View File

@@ -2,7 +2,13 @@
namespace CliFx.Demo.Domain;
public partial record Isbn(int EanPrefix, int RegistrationGroup, int Registrant, int Publication, int CheckDigit)
public partial record Isbn(
int EanPrefix,
int RegistrationGroup,
int Registrant,
int Publication,
int CheckDigit
)
{
public override string ToString() =>
$"{EanPrefix:000}-{RegistrationGroup:00}-{Registrant:00000}-{Publication:00}-{CheckDigit:0}";
@@ -22,4 +28,4 @@ public partial record Isbn
int.Parse(components[4], formatProvider)
);
}
}
}

View File

@@ -25,4 +25,4 @@ public partial record Library(IReadOnlyList<Book> Books)
public partial record Library
{
public static Library Empty { get; } = new(Array.Empty<Book>());
}
}

View File

@@ -6,7 +6,8 @@ namespace CliFx.Demo.Domain;
public class LibraryProvider
{
private static string StorageFilePath { get; } = Path.Combine(Directory.GetCurrentDirectory(), "Library.json");
private static string StorageFilePath { get; } =
Path.Combine(Directory.GetCurrentDirectory(), "Library.json");
private void StoreLibrary(Library library)
{
@@ -24,7 +25,8 @@ public class LibraryProvider
return JsonSerializer.Deserialize<Library>(data) ?? Library.Empty;
}
public Book? TryGetBook(string title) => GetLibrary().Books.FirstOrDefault(b => b.Title == title);
public Book? TryGetBook(string title) =>
GetLibrary().Books.FirstOrDefault(b => b.Title == title);
public void AddBook(Book book)
{
@@ -37,4 +39,4 @@ public class LibraryProvider
var updatedLibrary = GetLibrary().WithoutBook(book);
StoreLibrary(updatedLibrary);
}
}
}

View File

@@ -18,4 +18,4 @@ return await new CliApplicationBuilder()
return services.BuildServiceProvider();
})
.Build()
.RunAsync();
.RunAsync();

View File

@@ -33,4 +33,4 @@ internal static class ConsoleExtensions
using (writer.Console.WithForegroundColor(ConsoleColor.White))
writer.WriteLine(book.Isbn);
}
}
}