Skip to content

Commit 423e5f1

Browse files
committed
refactor to C# 14 extension methods
migrate static extension methods to C# 14 syntax.
1 parent 382fa3a commit 423e5f1

File tree

5 files changed

+537
-512
lines changed

5 files changed

+537
-512
lines changed

build/common/Addins/GitVersion/GitVersionAliases.cs

Lines changed: 89 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,97 +13,99 @@ namespace Common.Addins.GitVersion;
1313
[CakeAliasCategory("GitVersion")]
1414
public static class GitVersionAliases
1515
{
16-
/// <summary>
17-
/// Retrieves the GitVersion output.
18-
/// </summary>
1916
/// <param name="context">The context.</param>
20-
/// <returns>The Git version info.</returns>
21-
/// <example>
22-
/// <para>Update the assembly info files for the project.</para>
23-
/// <para>Cake task:</para>
24-
/// <code>
25-
/// <![CDATA[
26-
/// Task("UpdateAssemblyInfo")
27-
/// .Does(() =>
28-
/// {
29-
/// GitVersion(new GitVersionSettings {
30-
/// UpdateAssemblyInfo = true
31-
/// });
32-
/// });
33-
/// ]]>
34-
/// </code>
35-
/// <para>Get the Git version info for the project using a dynamic repository.</para>
36-
/// <para>Cake task:</para>
37-
/// <code>
38-
/// <![CDATA[
39-
/// Task("GetVersionInfo")
40-
/// .Does(() =>
41-
/// {
42-
/// var result = GitVersion(new GitVersionSettings {
43-
/// UserName = "MyUser",
44-
/// Password = "MyPassword,
45-
/// Url = "http://git.myhost.com/myproject.git"
46-
/// Branch = "develop"
47-
/// Commit = EnvironmentVariable("MY_COMMIT")
48-
/// });
49-
/// // Use result for building NuGet packages, setting build server version, etc...
50-
/// });
51-
/// ]]>
52-
/// </code>
53-
/// </example>
54-
[CakeMethodAlias]
55-
public static GitVersion GitVersion(this ICakeContext context)
17+
extension(ICakeContext context)
5618
{
57-
ArgumentNullException.ThrowIfNull(context);
19+
/// <summary>
20+
/// Retrieves the GitVersion output.
21+
/// </summary>
22+
/// <returns>The Git version info.</returns>
23+
/// <example>
24+
/// <para>Update the assembly info files for the project.</para>
25+
/// <para>Cake task:</para>
26+
/// <code>
27+
/// <![CDATA[
28+
/// Task("UpdateAssemblyInfo")
29+
/// .Does(() =>
30+
/// {
31+
/// GitVersion(new GitVersionSettings {
32+
/// UpdateAssemblyInfo = true
33+
/// });
34+
/// });
35+
/// ]]>
36+
/// </code>
37+
/// <para>Get the Git version info for the project using a dynamic repository.</para>
38+
/// <para>Cake task:</para>
39+
/// <code>
40+
/// <![CDATA[
41+
/// Task("GetVersionInfo")
42+
/// .Does(() =>
43+
/// {
44+
/// var result = GitVersion(new GitVersionSettings {
45+
/// UserName = "MyUser",
46+
/// Password = "MyPassword,
47+
/// Url = "http://git.myhost.com/myproject.git"
48+
/// Branch = "develop"
49+
/// Commit = EnvironmentVariable("MY_COMMIT")
50+
/// });
51+
/// // Use result for building NuGet packages, setting build server version, etc...
52+
/// });
53+
/// ]]>
54+
/// </code>
55+
/// </example>
56+
[CakeMethodAlias]
57+
public GitVersion GitVersion()
58+
{
59+
ArgumentNullException.ThrowIfNull(context);
5860

59-
return GitVersion(context, new GitVersionSettings());
60-
}
61+
return GitVersion(context, new GitVersionSettings());
62+
}
6163

62-
/// <summary>
63-
/// Retrieves the GitVersion output.
64-
/// </summary>
65-
/// <param name="context">The context.</param>
66-
/// <param name="settings">The GitVersion settings.</param>
67-
/// <returns>The Git version info.</returns>
68-
/// <example>
69-
/// <para>Update the assembly info files for the project.</para>
70-
/// <para>Cake task:</para>
71-
/// <code>
72-
/// <![CDATA[
73-
/// Task("UpdateAssemblyInfo")
74-
/// .Does(() =>
75-
/// {
76-
/// GitVersion(new GitVersionSettings {
77-
/// UpdateAssemblyInfo = true
78-
/// });
79-
/// });
80-
/// ]]>
81-
/// </code>
82-
/// <para>Get the Git version info for the project using a dynamic repository.</para>
83-
/// <para>Cake task:</para>
84-
/// <code>
85-
/// <![CDATA[
86-
/// Task("GetVersionInfo")
87-
/// .Does(() =>
88-
/// {
89-
/// var result = GitVersion(new GitVersionSettings {
90-
/// UserName = "MyUser",
91-
/// Password = "MyPassword,
92-
/// Url = "http://git.myhost.com/myproject.git"
93-
/// Branch = "develop"
94-
/// Commit = EnvironmentVariable("MY_COMMIT")
95-
/// });
96-
/// // Use result for building NuGet packages, setting build server version, etc...
97-
/// });
98-
/// ]]>
99-
/// </code>
100-
/// </example>
101-
[CakeMethodAlias]
102-
public static GitVersion GitVersion(this ICakeContext context, GitVersionSettings settings)
103-
{
104-
ArgumentNullException.ThrowIfNull(context);
64+
/// <summary>
65+
/// Retrieves the GitVersion output.
66+
/// </summary>
67+
/// <param name="settings">The GitVersion settings.</param>
68+
/// <returns>The Git version info.</returns>
69+
/// <example>
70+
/// <para>Update the assembly info files for the project.</para>
71+
/// <para>Cake task:</para>
72+
/// <code>
73+
/// <![CDATA[
74+
/// Task("UpdateAssemblyInfo")
75+
/// .Does(() =>
76+
/// {
77+
/// GitVersion(new GitVersionSettings {
78+
/// UpdateAssemblyInfo = true
79+
/// });
80+
/// });
81+
/// ]]>
82+
/// </code>
83+
/// <para>Get the Git version info for the project using a dynamic repository.</para>
84+
/// <para>Cake task:</para>
85+
/// <code>
86+
/// <![CDATA[
87+
/// Task("GetVersionInfo")
88+
/// .Does(() =>
89+
/// {
90+
/// var result = GitVersion(new GitVersionSettings {
91+
/// UserName = "MyUser",
92+
/// Password = "MyPassword,
93+
/// Url = "http://git.myhost.com/myproject.git"
94+
/// Branch = "develop"
95+
/// Commit = EnvironmentVariable("MY_COMMIT")
96+
/// });
97+
/// // Use result for building NuGet packages, setting build server version, etc...
98+
/// });
99+
/// ]]>
100+
/// </code>
101+
/// </example>
102+
[CakeMethodAlias]
103+
public GitVersion GitVersion(GitVersionSettings settings)
104+
{
105+
ArgumentNullException.ThrowIfNull(context);
105106

106-
var gitVersionRunner = new GitVersionRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log);
107-
return gitVersionRunner.Run(settings);
107+
var gitVersionRunner = new GitVersionRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log);
108+
return gitVersionRunner.Run(settings);
109+
}
108110
}
109111
}

build/common/Utilities/CakeHostExtensions.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ namespace Common.Utilities;
44

55
public static class ServicesExtensions
66
{
7-
public static CakeHost UseRootDirectory(this CakeHost host)
7+
extension(CakeHost host)
88
{
9-
host = host.ConfigureServices(services => services.UseWorkingDirectory(Extensions.GetRootDirectory()));
10-
return host;
11-
}
9+
public CakeHost UseRootDirectory()
10+
{
11+
host = host.ConfigureServices(services => services.UseWorkingDirectory(Extensions.GetRootDirectory()));
12+
return host;
13+
}
1214

13-
public static CakeHost InstallToolsFromRootManifest(this CakeHost host)
14-
{
15-
host = host.UseModule<LocalToolsModule>().InstallToolsFromManifest(Extensions.GetRootDirectory().CombineWithFilePath(".config/dotnet-tools.json").FullPath);
16-
return host;
17-
}
15+
public CakeHost InstallToolsFromRootManifest()
16+
{
17+
host = host.UseModule<LocalToolsModule>().InstallToolsFromManifest(Extensions.GetRootDirectory().CombineWithFilePath(".config/dotnet-tools.json").FullPath);
18+
return host;
19+
}
1820

19-
public static CakeHost InstallNugetTool(this CakeHost host, string toolName, string toolVersion)
20-
{
21-
var toolUrl = new Uri($"nuget:?package={toolName}&version={toolVersion}");
22-
return host.ConfigureServices(services => services.UseTool(toolUrl));
21+
public CakeHost InstallNugetTool(string toolName, string toolVersion)
22+
{
23+
var toolUrl = new Uri($"nuget:?package={toolName}&version={toolVersion}");
24+
return host.ConfigureServices(services => services.UseTool(toolUrl));
25+
}
2326
}
2427
}

0 commit comments

Comments
 (0)