From 380c622f7180804758ce1233c5a91c8a92335c74 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Mon, 22 Apr 2024 16:08:12 +0800 Subject: [PATCH 01/13] Add a new constructor that sets the version expected by the client Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index 62d36f56..dd3260e5 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -29,6 +29,26 @@ public TaskName(string name) } } + /// + /// Initializes a new instance of the struct. + /// + /// The name of the task. Providing null will yield the default struct. + /// The version of the task. + public TaskName(string name, string version) + { + if (name is null) + { + // Force the default struct when null is passed in. + this.Name = null!; + this.Version = version!; + } + else + { + this.Name = name; + this.Version = version; + } + } + /// /// Gets the name of the task without the version. /// From 1976de60e1d85593c9850cfae39caa12787241b5 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Mon, 22 Apr 2024 16:08:54 +0800 Subject: [PATCH 02/13] Add new abstract method to get instance version Signed-off-by: Sky Ao --- src/Abstractions/TaskOrchestrationContext.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Abstractions/TaskOrchestrationContext.cs b/src/Abstractions/TaskOrchestrationContext.cs index 15ba1ddc..5bb6fa4f 100644 --- a/src/Abstractions/TaskOrchestrationContext.cs +++ b/src/Abstractions/TaskOrchestrationContext.cs @@ -22,6 +22,11 @@ public abstract class TaskOrchestrationContext /// public abstract string InstanceId { get; } + /// + /// Gets the version of the current orchestration instance. + /// + public abstract string InstanceVersion { get; } + /// /// Gets the parent instance or null if there is no parent orchestration. /// From 4e1f8cb0aba467ba5fd97ce4e6483349b70a928a Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Mon, 22 Apr 2024 16:24:15 +0800 Subject: [PATCH 03/13] Implemented new added abstract method to get instance version Signed-off-by: Sky Ao --- src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs index 608a7038..f5a686f9 100644 --- a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs +++ b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs @@ -51,6 +51,9 @@ public TaskOrchestrationContextWrapper( /// public override string InstanceId => this.innerContext.OrchestrationInstance.InstanceId; + /// + public override string InstanceVersion => this.innerContext.OrchestrationInstance.InstanceVersion; + /// public override ParentOrchestrationInstance? Parent => this.invocationContext.Parent; From f6162ff4662a9a929a66355de3a111f2bf430cf8 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Tue, 23 Apr 2024 20:16:11 +0800 Subject: [PATCH 04/13] change to get instance version from this.innerContext.Version Signed-off-by: Sky Ao --- src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs index f5a686f9..a2448fae 100644 --- a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs +++ b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs @@ -52,7 +52,7 @@ public TaskOrchestrationContextWrapper( public override string InstanceId => this.innerContext.OrchestrationInstance.InstanceId; /// - public override string InstanceVersion => this.innerContext.OrchestrationInstance.InstanceVersion; + public override string InstanceVersion => this.innerContext.Version; /// public override ParentOrchestrationInstance? Parent => this.invocationContext.Parent; From d9298d0f811ed9085c07c63b04687e0047715155 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Fri, 26 Apr 2024 16:46:21 +0800 Subject: [PATCH 05/13] change InstanceVersion to virtual and return null be default to avoid breaking change. Signed-off-by: Sky Ao --- src/Abstractions/TaskOrchestrationContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abstractions/TaskOrchestrationContext.cs b/src/Abstractions/TaskOrchestrationContext.cs index 5bb6fa4f..89d3b677 100644 --- a/src/Abstractions/TaskOrchestrationContext.cs +++ b/src/Abstractions/TaskOrchestrationContext.cs @@ -25,7 +25,7 @@ public abstract class TaskOrchestrationContext /// /// Gets the version of the current orchestration instance. /// - public abstract string InstanceVersion { get; } + public virtual string? InstanceVersion => null; /// /// Gets the parent instance or null if there is no parent orchestration. From 83bc22739c997437eab90c8d17ffcf40355a0c5d Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Tue, 21 May 2024 10:01:47 +0800 Subject: [PATCH 06/13] update constructor to handle null correctly Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 257 ++++++++++++++++++----------------- 1 file changed, 136 insertions(+), 121 deletions(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index dd3260e5..664f94fd 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -8,147 +8,162 @@ namespace Microsoft.DurableTask; /// public readonly struct TaskName : IEquatable { - // TODO: Add detailed remarks that describe the role of TaskName + // TODO: Add detailed remarks that describe the role of TaskName - /// - /// Initializes a new instance of the struct. - /// - /// The name of the task. Providing null will yield the default struct. - public TaskName(string name) + /// + /// Initializes a new instance of the struct. + /// + /// The name of the task. Providing null will yield the default struct. + public TaskName(string name) + { + if (name is null) { - if (name is null) - { - // Force the default struct when null is passed in. - this.Name = null!; - this.Version = null!; - } - else - { - this.Name = name; - this.Version = string.Empty; // expose setting Version only when we actually consume it. - } + // Force the default struct when null is passed in. + this.Name = null!; + this.Version = null!; } + else + { + this.Name = name; + this.Version = string.Empty; // expose setting Version only when we actually consume it. + } + } - /// - /// Initializes a new instance of the struct. - /// - /// The name of the task. Providing null will yield the default struct. - /// The version of the task. - public TaskName(string name, string version) + /// + /// Initializes a new instance of the struct. + /// + /// The name of the task. Providing null will yield the default struct. + /// The version of the task. + public TaskName(string name, string version) + { + if (name is null) + { + if (version is null) + { + // Force the default struct when null is passed in. + this.Name = null!; + this.Version = null!; + } + else + { + throw new ArgumentException("name must not be null when version is non-null"); + } + } + else { - if (name is null) - { - // Force the default struct when null is passed in. - this.Name = null!; - this.Version = version!; - } - else - { - this.Name = name; - this.Version = version; - } + if (version is null) + { + this.Name = name; + this.Version = string.Empty; // fallback to the contructor without version parameter + } + else + { + this.Name = name; + this.Version = version; + } } + } - /// - /// Gets the name of the task without the version. - /// - /// - /// The name of the activity task without the version. - /// - public string Name { get; } + /// + /// Gets the name of the task without the version. + /// + /// + /// The name of the activity task without the version. + /// + public string Name { get; } - /// - /// Gets the version of the task. - /// - /// - /// Task versions is currently locked to as it is not yet integrated into task - /// identification. This is being left here as we intend to support it soon. - /// - public string Version { get; } + /// + /// Gets the version of the task. + /// + /// + /// Task versions is currently locked to as it is not yet integrated into task + /// identification. This is being left here as we intend to support it soon. + /// + public string Version { get; } - /// - /// Implicitly converts a into a of the property value. - /// - /// The to be converted into a string. - public static implicit operator string(TaskName value) => value.Name; + /// + /// Implicitly converts a into a of the property value. + /// + /// The to be converted into a string. + public static implicit operator string(TaskName value) => value.Name; - /// - /// Implicitly converts a into a value. - /// - /// The string to convert into a . - public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value); + /// + /// Implicitly converts a into a value. + /// + /// The string to convert into a . + public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value); - /// - /// Compares two objects for equality. - /// - /// The first to compare. - /// The second to compare. - /// true if the two objects are equal; otherwise false. - public static bool operator ==(TaskName a, TaskName b) - { - return a.Equals(b); - } + /// + /// Compares two objects for equality. + /// + /// The first to compare. + /// The second to compare. + /// true if the two objects are equal; otherwise false. + public static bool operator ==(TaskName a, TaskName b) + { + return a.Equals(b); + } - /// - /// Compares two objects for inequality. - /// - /// The first to compare. - /// The second to compare. - /// true if the two objects are not equal; otherwise false. - public static bool operator !=(TaskName a, TaskName b) - { - return !a.Equals(b); - } + /// + /// Compares two objects for inequality. + /// + /// The first to compare. + /// The second to compare. + /// true if the two objects are not equal; otherwise false. + public static bool operator !=(TaskName a, TaskName b) + { + return !a.Equals(b); + } + + /// + /// Gets a value indicating whether to objects + /// are equal using value semantics. + /// + /// The other object to compare to. + /// true if the two objects are equal using value semantics; otherwise false. + public bool Equals(TaskName other) + { + return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase); + } - /// - /// Gets a value indicating whether to objects - /// are equal using value semantics. - /// - /// The other object to compare to. - /// true if the two objects are equal using value semantics; otherwise false. - public bool Equals(TaskName other) + /// + /// Gets a value indicating whether to objects + /// are equal using value semantics. + /// + /// The other object to compare to. + /// true if the two objects are equal using value semantics; otherwise false. + public override bool Equals(object? obj) + { + if (obj is not TaskName other) { - return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase); + return false; } - /// - /// Gets a value indicating whether to objects - /// are equal using value semantics. - /// - /// The other object to compare to. - /// true if the two objects are equal using value semantics; otherwise false. - public override bool Equals(object? obj) - { - if (obj is not TaskName other) - { - return false; - } + return this.Equals(other); + } - return this.Equals(other); - } + /// + /// Calculates a hash code value for the current instance. + /// + /// A 32-bit hash code value. + public override int GetHashCode() + { + return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + } - /// - /// Calculates a hash code value for the current instance. - /// - /// A 32-bit hash code value. - public override int GetHashCode() + /// + /// Gets the string value of the current instance. + /// + /// The name and optional version of the current instance. + public override string ToString() + { + if (string.IsNullOrEmpty(this.Version)) { - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + return this.Name; } - - /// - /// Gets the string value of the current instance. - /// - /// The name and optional version of the current instance. - public override string ToString() + else { - if (string.IsNullOrEmpty(this.Version)) - { - return this.Name; - } - else - { - return this.Name + ":" + this.Version; - } + return this.Name + ":" + this.Version; } + } } From 0045ced10f24641517e4da41197a6753dedead51 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Wed, 10 Jul 2024 15:36:25 +0800 Subject: [PATCH 07/13] update Equals/GetHashCode method to include version field Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index 664f94fd..a9931071 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -123,7 +123,8 @@ public TaskName(string name, string version) /// true if the two objects are equal using value semantics; otherwise false. public bool Equals(TaskName other) { - return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase); + return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase) + && string.Equals(this.Version, other.Version, StringComparison.OrdinalIgnoreCase); } /// @@ -148,7 +149,13 @@ public override bool Equals(object? obj) /// A 32-bit hash code value. public override int GetHashCode() { - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + if (string.IsNullOrEmpty(this.Version)) + { + return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + } + + return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name) * 31 + + StringComparer.OrdinalIgnoreCase.GetHashCode(this.Version); } /// From 2172e961e3ecf1874e7915a3a14a7cd268067550 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Wed, 10 Jul 2024 15:40:03 +0800 Subject: [PATCH 08/13] use value.ToString() to include version field Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index a9931071..df6f94a2 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -85,7 +85,7 @@ public TaskName(string name, string version) /// Implicitly converts a into a of the property value. /// /// The to be converted into a string. - public static implicit operator string(TaskName value) => value.Name; + public static implicit operator string(TaskName value) => value.ToString(); /// /// Implicitly converts a into a value. From 5c3ad58a632534a3976442240634998d03f302a1 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Tue, 16 Jul 2024 15:41:48 +0800 Subject: [PATCH 09/13] rollback file formator to use 4 space indentation Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 294 +++++++++++++++++------------------ 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index df6f94a2..009a9b31 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -8,169 +8,169 @@ namespace Microsoft.DurableTask; /// public readonly struct TaskName : IEquatable { - // TODO: Add detailed remarks that describe the role of TaskName - - /// - /// Initializes a new instance of the struct. - /// - /// The name of the task. Providing null will yield the default struct. - public TaskName(string name) - { - if (name is null) + // TODO: Add detailed remarks that describe the role of TaskName + + /// + /// Initializes a new instance of the struct. + /// + /// The name of the task. Providing null will yield the default struct. + public TaskName(string name) { - // Force the default struct when null is passed in. - this.Name = null!; - this.Version = null!; + if (name is null) + { + // Force the default struct when null is passed in. + this.Name = null!; + this.Version = null!; + } + else + { + this.Name = name; + this.Version = string.Empty; // expose setting Version only when we actually consume it. + } } - else + + /// + /// Initializes a new instance of the struct. + /// + /// The name of the task. Providing null will yield the default struct. + /// The version of the task. + public TaskName(string name, string version) { - this.Name = name; - this.Version = string.Empty; // expose setting Version only when we actually consume it. + if (name is null) + { + if (version is null) + { + // Force the default struct when null is passed in. + this.Name = null!; + this.Version = null!; + } + else + { + throw new ArgumentException("name must not be null when version is non-null"); + } + } + else + { + if (version is null) + { + this.Name = name; + this.Version = string.Empty; // fallback to the contructor without version parameter + } + else + { + this.Name = name; + this.Version = version; + } + } } - } - - /// - /// Initializes a new instance of the struct. - /// - /// The name of the task. Providing null will yield the default struct. - /// The version of the task. - public TaskName(string name, string version) - { - if (name is null) + + /// + /// Gets the name of the task without the version. + /// + /// + /// The name of the activity task without the version. + /// + public string Name { get; } + + /// + /// Gets the version of the task. + /// + /// + /// Task versions is currently locked to as it is not yet integrated into task + /// identification. This is being left here as we intend to support it soon. + /// + public string Version { get; } + + /// + /// Implicitly converts a into a of the property value. + /// + /// The to be converted into a string. + public static implicit operator string(TaskName value) => value.ToString(); + + /// + /// Implicitly converts a into a value. + /// + /// The string to convert into a . + public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value); + + /// + /// Compares two objects for equality. + /// + /// The first to compare. + /// The second to compare. + /// true if the two objects are equal; otherwise false. + public static bool operator ==(TaskName a, TaskName b) { - if (version is null) - { - // Force the default struct when null is passed in. - this.Name = null!; - this.Version = null!; - } - else - { - throw new ArgumentException("name must not be null when version is non-null"); - } + return a.Equals(b); } - else + + /// + /// Compares two objects for inequality. + /// + /// The first to compare. + /// The second to compare. + /// true if the two objects are not equal; otherwise false. + public static bool operator !=(TaskName a, TaskName b) { - if (version is null) - { - this.Name = name; - this.Version = string.Empty; // fallback to the contructor without version parameter - } - else - { - this.Name = name; - this.Version = version; - } + return !a.Equals(b); } - } - - /// - /// Gets the name of the task without the version. - /// - /// - /// The name of the activity task without the version. - /// - public string Name { get; } - - /// - /// Gets the version of the task. - /// - /// - /// Task versions is currently locked to as it is not yet integrated into task - /// identification. This is being left here as we intend to support it soon. - /// - public string Version { get; } - - /// - /// Implicitly converts a into a of the property value. - /// - /// The to be converted into a string. - public static implicit operator string(TaskName value) => value.ToString(); - - /// - /// Implicitly converts a into a value. - /// - /// The string to convert into a . - public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value); - - /// - /// Compares two objects for equality. - /// - /// The first to compare. - /// The second to compare. - /// true if the two objects are equal; otherwise false. - public static bool operator ==(TaskName a, TaskName b) - { - return a.Equals(b); - } - - /// - /// Compares two objects for inequality. - /// - /// The first to compare. - /// The second to compare. - /// true if the two objects are not equal; otherwise false. - public static bool operator !=(TaskName a, TaskName b) - { - return !a.Equals(b); - } - - /// - /// Gets a value indicating whether to objects - /// are equal using value semantics. - /// - /// The other object to compare to. - /// true if the two objects are equal using value semantics; otherwise false. - public bool Equals(TaskName other) - { - return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase) - && string.Equals(this.Version, other.Version, StringComparison.OrdinalIgnoreCase); - } - - /// - /// Gets a value indicating whether to objects - /// are equal using value semantics. - /// - /// The other object to compare to. - /// true if the two objects are equal using value semantics; otherwise false. - public override bool Equals(object? obj) - { - if (obj is not TaskName other) + + /// + /// Gets a value indicating whether to objects + /// are equal using value semantics. + /// + /// The other object to compare to. + /// true if the two objects are equal using value semantics; otherwise false. + public bool Equals(TaskName other) { - return false; + return string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase) + && string.Equals(this.Version, other.Version, StringComparison.OrdinalIgnoreCase); } - return this.Equals(other); - } - - /// - /// Calculates a hash code value for the current instance. - /// - /// A 32-bit hash code value. - public override int GetHashCode() - { - if (string.IsNullOrEmpty(this.Version)) + /// + /// Gets a value indicating whether to objects + /// are equal using value semantics. + /// + /// The other object to compare to. + /// true if the two objects are equal using value semantics; otherwise false. + public override bool Equals(object? obj) { - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + if (obj is not TaskName other) + { + return false; + } + + return this.Equals(other); } - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name) * 31 - + StringComparer.OrdinalIgnoreCase.GetHashCode(this.Version); - } - - /// - /// Gets the string value of the current instance. - /// - /// The name and optional version of the current instance. - public override string ToString() - { - if (string.IsNullOrEmpty(this.Version)) + /// + /// Calculates a hash code value for the current instance. + /// + /// A 32-bit hash code value. + public override int GetHashCode() { - return this.Name; + if (string.IsNullOrEmpty(this.Version)) + { + return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); + } + + return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name) * 31 + + StringComparer.OrdinalIgnoreCase.GetHashCode(this.Version); } - else + + /// + /// Gets the string value of the current instance. + /// + /// The name and optional version of the current instance. + public override string ToString() { - return this.Name + ":" + this.Version; + if (string.IsNullOrEmpty(this.Version)) + { + return this.Name; + } + else + { + return this.Name + ":" + this.Version; + } } - } } From 7912d46be2877df98e19db3cdf15216f90dd758e Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Tue, 16 Jul 2024 15:45:26 +0800 Subject: [PATCH 10/13] use Microsoft.Bcl.HashCode to do hash Signed-off-by: Sky Ao --- src/Abstractions/Abstractions.csproj | 1 + src/Abstractions/TaskName.cs | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Abstractions/Abstractions.csproj b/src/Abstractions/Abstractions.csproj index 9c20cb8a..ef9bb8c2 100644 --- a/src/Abstractions/Abstractions.csproj +++ b/src/Abstractions/Abstractions.csproj @@ -9,6 +9,7 @@ + diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index 009a9b31..5efc6f06 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -149,13 +149,7 @@ public override bool Equals(object? obj) /// A 32-bit hash code value. public override int GetHashCode() { - if (string.IsNullOrEmpty(this.Version)) - { - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name); - } - - return StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name) * 31 - + StringComparer.OrdinalIgnoreCase.GetHashCode(this.Version); + return HashCode.Combine(this.Name, this.Version); } /// From d015d3ed80cadbce5446cc12ebc4fc60eba54268 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Tue, 16 Jul 2024 15:47:11 +0800 Subject: [PATCH 11/13] fix typo Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index 5efc6f06..bb54538d 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -54,7 +54,7 @@ public TaskName(string name, string version) if (version is null) { this.Name = name; - this.Version = string.Empty; // fallback to the contructor without version parameter + this.Version = string.Empty; // fallback to the constructor without version parameter } else { From 87b15e10b571228a2c597792787d532a5bb70825 Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Thu, 18 Jul 2024 14:57:54 +0800 Subject: [PATCH 12/13] udpate documents for version Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index bb54538d..f15a0041 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -75,10 +75,9 @@ public TaskName(string name, string version) /// /// Gets the version of the task. /// - /// - /// Task versions is currently locked to as it is not yet integrated into task - /// identification. This is being left here as we intend to support it soon. - /// + /// + /// The version of the activity task. + /// public string Version { get; } /// From 6ecfde18ddf14a11186074f7746d83ba3a6914ea Mon Sep 17 00:00:00 2001 From: Sky Ao Date: Thu, 18 Jul 2024 15:16:48 +0800 Subject: [PATCH 13/13] add static FromString() method and update the string conversion operator to call FromString() method Signed-off-by: Sky Ao --- src/Abstractions/TaskName.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Abstractions/TaskName.cs b/src/Abstractions/TaskName.cs index f15a0041..c39e912c 100644 --- a/src/Abstractions/TaskName.cs +++ b/src/Abstractions/TaskName.cs @@ -90,7 +90,7 @@ public TaskName(string name, string version) /// Implicitly converts a into a value. /// /// The string to convert into a . - public static implicit operator TaskName(string value) => string.IsNullOrEmpty(value) ? default : new(value); + public static implicit operator TaskName(string value) => FromString(value); /// /// Compares two objects for equality. @@ -114,6 +114,32 @@ public TaskName(string name, string version) return !a.Equals(b); } + /// + /// Parses the taskname string and initializes a new instance of the struct. + /// + /// The taskname string in format of "Name:Version" or "Name". + /// New instance parsed from taskname string. + public static TaskName FromString(string taskname) + { + if (string.IsNullOrEmpty(taskname)) + { + return default; + } + + string[] parts = taskname.Split(':'); + if (parts.Length == 1) + { + return new TaskName(parts[0]); + } + + if (parts.Length == 2) + { + return new TaskName(parts[0], parts[1]); + } + + throw new ArgumentException("Invalid task name format: taskname=" + taskname); + } + /// /// Gets a value indicating whether to objects /// are equal using value semantics.