Refactor syntax for new array initialization
Updated new array initialization syntax from `new[] {}` to `[]` across multiple files for consistency and code brevity. This change enhances readability and aligns with modern C# conventions.
This commit is contained in:
parent
10146cd661
commit
c311ba03ac
|
|
@ -29,7 +29,7 @@ public abstract class Trigger : Activity, ITrigger
|
|||
/// <summary>
|
||||
/// Override this method to return trigger data.
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) => new[] { GetTriggerPayload(context) };
|
||||
protected virtual IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) => [GetTriggerPayload(context)];
|
||||
|
||||
/// <summary>
|
||||
/// Override this method to return a trigger datum.
|
||||
|
|
@ -61,7 +61,7 @@ public abstract class Trigger<TResult> : Activity<TResult>, ITrigger
|
|||
/// <summary>
|
||||
/// Override this method to return a trigger payload.
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) => new[] { GetTriggerPayload(context) };
|
||||
protected virtual IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) => [GetTriggerPayload(context)];
|
||||
|
||||
/// <summary>
|
||||
/// Override this method to return a trigger payload.
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class Complete : Activity, ITerminalNode
|
|||
|
||||
/// <inheritdoc />
|
||||
public Complete(Func<ExpressionExecutionContext, string> outcome, [CallerFilePath] string? source = default, [CallerLineNumber] int? line = default)
|
||||
: this(context => new[] { outcome(context) }, source, line)
|
||||
: this(context => [outcome(context)], source, line)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Elsa.Workflows;
|
|||
public partial class ActivityExecutionContext : IExecutionContext, IDisposable
|
||||
{
|
||||
private readonly ISystemClock _systemClock;
|
||||
private readonly List<Bookmark> _bookmarks = new();
|
||||
private readonly List<Bookmark> _bookmarks = [];
|
||||
private long _executionCount;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ namespace Elsa.Extensions;
|
|||
/// </summary>
|
||||
public static class ActivityPropertyExtensions
|
||||
{
|
||||
private static readonly string[] CanStartWorkflowPropertyName = {"canStartWorkflow", "CanStartWorkflow", };
|
||||
private static readonly string[] RunAsynchronouslyPropertyName = {"runAsynchronously", "RunAsynchronously" };
|
||||
private static readonly string[] SourcePropertyName = {"source", "Source"};
|
||||
private static readonly string[] CanStartWorkflowPropertyName = ["canStartWorkflow", "CanStartWorkflow"];
|
||||
private static readonly string[] RunAsynchronouslyPropertyName = ["runAsynchronously", "RunAsynchronously"];
|
||||
private static readonly string[] SourcePropertyName = ["source", "Source"];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a flag indicating whether this activity can be used for starting a workflow.
|
||||
|
|
|
|||
|
|
@ -76,6 +76,6 @@ public static class BackgroundActivityExecutionContextExtensions
|
|||
/// <param name="activityExecutionContext"></param>
|
||||
public static IEnumerable<ScheduledActivity> GetBackgroundScheduledActivities(this ActivityExecutionContext activityExecutionContext)
|
||||
{
|
||||
return activityExecutionContext.GetProperty<IEnumerable<ScheduledActivity>>("BackgroundScheduledActivities") ?? Enumerable.Empty<ScheduledActivity>();
|
||||
return activityExecutionContext.GetProperty<IEnumerable<ScheduledActivity>>("BackgroundScheduledActivities") ?? [];
|
||||
}
|
||||
}
|
||||
|
|
@ -464,10 +464,9 @@ public static class ExpressionExecutionContextExtensions
|
|||
foreach (var output in activityDescriptor.Outputs)
|
||||
{
|
||||
var outputPascalName = output.Name.Pascalize();
|
||||
yield return new ActivityOutputs(activity.Id, activityIdPascalName, new[]
|
||||
{
|
||||
yield return new ActivityOutputs(activity.Id, activityIdPascalName, [
|
||||
outputPascalName
|
||||
});
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -548,9 +547,8 @@ public static class ExpressionExecutionContextExtensions
|
|||
return obj;
|
||||
|
||||
var toArrayMethod = typeof(Enumerable).GetMethod("ToArray")!.MakeGenericMethod(elementType);
|
||||
return toArrayMethod.Invoke(null, new object[]
|
||||
{
|
||||
return toArrayMethod.Invoke(null, [
|
||||
enumerable
|
||||
})!;
|
||||
])!;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ public class CustomConstructorConfigurator : SerializationOptionsConfiguratorBas
|
|||
{
|
||||
// If we have a default constructor, use that one.
|
||||
if (!constructor.GetParameters().Any())
|
||||
return () => constructor.Invoke(default, Array.Empty<object>())!;
|
||||
return () => constructor.Invoke(default, [])!;
|
||||
|
||||
// Else, find a constructor with the following signature: (string?, int?).
|
||||
// Check for a constructor with the following signature:
|
||||
|
|
@ -57,7 +57,7 @@ public class CustomConstructorConfigurator : SerializationOptionsConfiguratorBas
|
|||
parameters[1].DefaultValue != null ||
|
||||
(parameters[1].GetCustomAttribute<CallerLineNumberAttribute>() == null && !isJsonConstructor)) continue;
|
||||
|
||||
return () => constructor.Invoke(new object[] { null!, 0 });
|
||||
return () => constructor.Invoke([null!, 0]);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -21,14 +21,12 @@ public class ActivityVisitor : IActivityVisitor
|
|||
public async Task<ActivityNode> VisitAsync(IActivity activity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var graph = new ActivityNode(activity, "Root");
|
||||
var collectedNodes = new HashSet<ActivityNode>(new[]
|
||||
{
|
||||
var collectedNodes = new HashSet<ActivityNode>([
|
||||
graph
|
||||
});
|
||||
var collectedActivities = new HashSet<IActivity>(new[]
|
||||
{
|
||||
]);
|
||||
var collectedActivities = new HashSet<IActivity>([
|
||||
activity
|
||||
});
|
||||
]);
|
||||
var visitorContext = new ActivityVisitorContext
|
||||
{
|
||||
CollectedActivities = collectedActivities,
|
||||
|
|
@ -87,7 +85,7 @@ public class ActivityVisitor : IActivityVisitor
|
|||
|
||||
private class ActivityVisitorContext
|
||||
{
|
||||
public HashSet<IActivity> CollectedActivities { get; set; } = new();
|
||||
public HashSet<ActivityNode> CollectedNodes { get; set; } = new();
|
||||
public HashSet<IActivity> CollectedActivities { get; set; } = [];
|
||||
public HashSet<ActivityNode> CollectedNodes { get; set; } = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,6 @@ public class CheckListUIHintHandler : IUIHintHandler
|
|||
/// <inheritdoc />
|
||||
public ValueTask<IEnumerable<Type>> GetPropertyUIHandlersAsync(PropertyInfo propertyInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
return new(new[] { typeof(StaticCheckListOptionsProvider) });
|
||||
return new([typeof(StaticCheckListOptionsProvider)]);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,6 @@ public class DropDownUIHintHandler : IUIHintHandler
|
|||
/// <inheritdoc />
|
||||
public ValueTask<IEnumerable<Type>> GetPropertyUIHandlersAsync(PropertyInfo propertyInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
return new(new[] { typeof(StaticDropDownOptionsProvider) });
|
||||
return new([typeof(StaticDropDownOptionsProvider)]);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,6 @@ public class JsonEditorUIHintHandler : IUIHintHandler
|
|||
/// <inheritdoc />
|
||||
public ValueTask<IEnumerable<Type>> GetPropertyUIHandlersAsync(PropertyInfo propertyInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
return new(new[] { typeof(JsonCodeOptionsProvider) });
|
||||
return new([typeof(JsonCodeOptionsProvider)]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue