From fdc57945e81c6942e192dc5585eed5d21dfd0ce8 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 28 Mar 2025 20:44:15 +0100 Subject: [PATCH] Refactor default parameter values to use `null` instead of `default`. Replaced `default` with `null` for optional parameters across several classes to improve clarity and consistency. This change aligns with typical .NET conventions and ensures more predictable behavior when handling optional arguments. --- .../Elsa.Workflows.Core/Models/ActivityWorkItem.cs | 10 +++++----- .../Activities/PublishEvent.cs | 12 ++++++------ .../Services/EventPublisher.cs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Models/ActivityWorkItem.cs b/src/modules/Elsa.Workflows.Core/Models/ActivityWorkItem.cs index 2dc6b6b7f..863478774 100644 --- a/src/modules/Elsa.Workflows.Core/Models/ActivityWorkItem.cs +++ b/src/modules/Elsa.Workflows.Core/Models/ActivityWorkItem.cs @@ -12,11 +12,11 @@ public class ActivityWorkItem /// public ActivityWorkItem( IActivity activity, - ActivityExecutionContext? owner = default, - object? tag = default, - IEnumerable? variables = default, - ActivityExecutionContext? existingActivityExecutionContext = default, - IDictionary? input = default) + ActivityExecutionContext? owner = null, + object? tag = null, + IEnumerable? variables = null, + ActivityExecutionContext? existingActivityExecutionContext = null, + IDictionary? input = null) { Activity = activity; Owner = owner; diff --git a/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs b/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs index 3b37f6c62..9e7ca40be 100644 --- a/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs +++ b/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs @@ -14,7 +14,7 @@ namespace Elsa.Workflows.Runtime.Activities; public class PublishEvent : Activity { /// - public PublishEvent([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) + public PublishEvent([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) { } @@ -22,25 +22,25 @@ public class PublishEvent : Activity /// The name of the event to publish. /// [Input(Description = "The name of the event to publish.")] - public Input EventName { get; set; } = default!; + public Input EventName { get; set; } = null!; /// /// The correlation ID to scope the event to. /// [Input(Description = "The correlation ID to scope the event to.")] - public Input CorrelationId { get; set; } = default!; + public Input CorrelationId { get; set; } = null!; /// /// Whether the event is local to the workflow. /// [Input(DisplayName = "Local event", Description = "Whether the event is local to the workflow. When checked, the event will be delivered to this workflow instance only.")] - public Input IsLocalEvent { get; set; } = default!; + public Input IsLocalEvent { get; set; } = null!; /// /// The input to send as the event body. /// [Input(Description = "The payload to send as the event body.")] - public Input Payload { get; set; } = default!; + public Input Payload { get; set; } = null!; /// protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) @@ -48,7 +48,7 @@ public class PublishEvent : Activity var eventName = EventName.Get(context); var correlationId = CorrelationId.GetOrDefault(context); var isLocalEvent = IsLocalEvent.GetOrDefault(context); - var workflowInstanceId = isLocalEvent ? context.WorkflowExecutionContext.Id : default; + var workflowInstanceId = isLocalEvent ? context.WorkflowExecutionContext.Id : null; var payload = Payload.GetOrDefault(context); var publisher = context.GetRequiredService(); diff --git a/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs b/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs index c81e87d74..eaf00245e 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs @@ -9,10 +9,10 @@ public class EventPublisher(IStimulusSender stimulusSender) : IEventPublisher /// public async Task PublishAsync( string eventName, - string? correlationId = default, - string? workflowInstanceId = default, - string? activityInstanceId = default, - object? payload = default, + string? correlationId = null, + string? workflowInstanceId = null, + string? activityInstanceId = null, + object? payload = null, CancellationToken cancellationToken = default) { var stimulus = new EventStimulus(eventName);