Skip to content

Commit 4cd811b

Browse files
committed
Add version to TaskName
This commit adds an explict set for Version in TaskName. It also includes a flag that is set so other code can determine if the TaskName is intended to be versioned. Finally, it updates the Version property in the TaskOrchestrationContext as that was always set to empty instead of being able to be used. Signed-off-by: halspang <[email protected]>
1 parent 33ec0d7 commit 4cd811b

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/Abstractions/TaskName.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System;
5+
46
namespace Microsoft.DurableTask;
57

68
/// <summary>
@@ -25,7 +27,31 @@ public TaskName(string name)
2527
else
2628
{
2729
this.Name = name;
28-
this.Version = string.Empty; // expose setting Version only when we actually consume it.
30+
this.Version = string.Empty;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="TaskName"/> struct.
36+
/// </summary>
37+
/// <remarks>
38+
/// This <c>TaskName</c> is explicitly versioned, as compared to the default value.
39+
/// </remarks>
40+
/// <param name="name">The name of the task. Providing <c>null</c> will yield the default struct, ignoring the version.</param>
41+
/// <param name="version">Optional. The version of the task. Providing <c>null</c> will yield the default value.</param>
42+
public TaskName(string name, string version)
43+
{
44+
if (name is null)
45+
{
46+
// Force the default struct when null is passed in.
47+
this.Name = null!;
48+
this.Version = null!;
49+
}
50+
else
51+
{
52+
this.IsVersioned = true;
53+
this.Name = name;
54+
this.Version = version == null ? null! : version;
2955
}
3056
}
3157

@@ -46,6 +72,14 @@ public TaskName(string name)
4672
/// </remarks>
4773
public string Version { get; }
4874

75+
/// <summary>
76+
/// Gets the flag denoting if this TaskName is versioned.
77+
/// </summary>
78+
/// <remarks>
79+
/// This flag is used to distinguish between the default (empty version) and a Task with an explicit empty version.
80+
/// </remarks>
81+
public bool IsVersioned { get; } = false;
82+
4983
/// <summary>
5084
/// Implicitly converts a <see cref="TaskName"/> into a <see cref="string"/> of the <see cref="Name"/> property value.
5185
/// </summary>

src/Abstractions/TaskOrchestrationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public abstract class TaskOrchestrationContext
6161
public abstract bool IsReplaying { get; }
6262

6363
/// <summary>
64-
/// Gets the version of the current orchestration instance, which was set when the instance was created.
64+
/// Gets or sets the version of the current orchestration instance, which was set when the instance was created.
6565
/// </summary>
66-
public virtual string Version => string.Empty;
66+
public virtual string Version { get; protected internal set; } = string.Empty;
6767

6868
/// <summary>
6969
/// Gets the entity feature, for interacting with entities.

0 commit comments

Comments
 (0)