From 3133f5d22a93b5782892ac37986a536f60b715ed Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Wed, 14 Jan 2026 12:49:12 +0100 Subject: [PATCH] Refactor ProjectCollection to primary constructor record and update dependencies - Convert ProjectCollection from class to primary constructor record - Change computed properties to ICollection with lazy initialization using field pattern - Update Microsoft.Extensions.DependencyInjection to 9.0.12 (net9.0) and 10.0.2 (net10.0) - Remove nullable annotation from fallbackVersion field --- build/helpers.cs | 27 ++++++++++--------- build/version.cs | 2 +- samples/Example.csproj | 2 +- ....Cli.Extensions.DependencyInjection.csproj | 4 +-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/build/helpers.cs b/build/helpers.cs index 091c621..0207424 100644 --- a/build/helpers.cs +++ b/build/helpers.cs @@ -20,21 +20,22 @@ static ProjectCollection GetProjects(ConvertableFilePath slnPath, string configu var solution = ParseSolution(slnPath); var projects = solution.Projects.Where(p => p.Type != "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"); var testAssemblies = projects.Where(p => p.Name.Contains(".Tests")).Select(p => p.Path.GetDirectory() + "/bin/" + configuration + "/" + p.Name + ".dll"); - return new ProjectCollection { - SolutionPath = slnPath, - SourceProjects = projects.Where(p => !p.Name.Contains(".Tests")), - TestProjects = projects.Where(p => p.Name.Contains(".Tests")) - }; + return new ProjectCollection( + SolutionPath: slnPath, + SourceProjects: projects.Where(p => !p.Name.Contains(".Tests")), + TestProjects: projects.Where(p => p.Name.Contains(".Tests")) + ); } } -public class ProjectCollection { - public ConvertableFilePath SolutionPath { get; set;} - public IEnumerable SourceProjects { get; set;} - public IEnumerable SourceProjectPaths {get { return SourceProjects.Select(p => p.Path.GetDirectory()); } } - public IEnumerable TestProjects {get;set;} - public IEnumerable TestProjectPaths { get { return TestProjects.Select(p => p.Path.GetDirectory()); } } - public IEnumerable AllProjects { get { return SourceProjects.Concat(TestProjects); } } - public IEnumerable AllProjectPaths { get { return AllProjects.Select(p => p.Path.GetDirectory()); } } +public record ProjectCollection( + ConvertableFilePath SolutionPath, + IEnumerable SourceProjects, + IEnumerable TestProjects) +{ + public ICollection SourceProjectPaths => field ??= [.. SourceProjects.Select(p => p.Path.GetDirectory())]; + public ICollection TestProjectPaths => field ??= [.. TestProjects.Select(p => p.Path.GetDirectory())]; + public ICollection AllProjects => field ??= [.. SourceProjects.Concat(TestProjects)]; + public ICollection AllProjectPaths => field ??= [.. AllProjects.Select(p => p.Path.GetDirectory())]; } \ No newline at end of file diff --git a/build/version.cs b/build/version.cs index 89aaf32..1975c0f 100644 --- a/build/version.cs +++ b/build/version.cs @@ -1,6 +1,6 @@ public static partial class Program { - private static string? fallbackVersion = Argument("force-version", EnvironmentVariable("FALLBACK_VERSION") ?? "0.1.0"); + private static string fallbackVersion = Argument("force-version", EnvironmentVariable("FALLBACK_VERSION") ?? "0.1.0"); static string BuildVersion(string fallbackVersion) { var PackageVersion = string.Empty; diff --git a/samples/Example.csproj b/samples/Example.csproj index 877e5bc..761c9a2 100644 --- a/samples/Example.csproj +++ b/samples/Example.csproj @@ -18,7 +18,7 @@ - + \ No newline at end of file diff --git a/src/Spectre.Console.Cli.Extensions.DependencyInjection/Spectre.Console.Cli.Extensions.DependencyInjection.csproj b/src/Spectre.Console.Cli.Extensions.DependencyInjection/Spectre.Console.Cli.Extensions.DependencyInjection.csproj index caf4b9f..dfbe358 100644 --- a/src/Spectre.Console.Cli.Extensions.DependencyInjection/Spectre.Console.Cli.Extensions.DependencyInjection.csproj +++ b/src/Spectre.Console.Cli.Extensions.DependencyInjection/Spectre.Console.Cli.Extensions.DependencyInjection.csproj @@ -18,8 +18,8 @@ - - + +