Skip to content

Commit

Permalink
Use some .NET 9 features.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKWatkins committed Nov 17, 2024
1 parent 8dedba6 commit dee9843
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/MrKWatkins.Ast/Node.Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MrKWatkins.Ast;
public abstract partial class Node<TNode>
where TNode : Node<TNode>
{
private readonly object messagesLock = new();
private readonly Lock messagesLock = new();
private ImmutableList<Message> messages = ImmutableList<Message>.Empty;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/MrKWatkins.Ast/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected Node()
/// </summary>
/// <param name="children">The children to add.</param>
/// <exception cref="InvalidOperationException">If any of <see cref="Children" /> already have a <see cref="Parent" />.</exception>
protected Node([InstantHandle] IEnumerable<TNode> children)
protected Node([InstantHandle] params IEnumerable<TNode> children)
{
Children = new Children<TNode>(This, children);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MrKWatkins.Ast/Position/BinaryFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BinaryFilePosition CreatePosition(int startIndex, int length) =>
public BinaryFilePosition CreateEntireFilePosition() => new(this, 0, Length);

[Pure]
private static IReadOnlyList<byte> ReadStream(Stream stream)
private static byte[] ReadStream(Stream stream)
{
using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
Expand Down
13 changes: 6 additions & 7 deletions src/MrKWatkins.Ast/Processing/PipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public PipelineBuilder<TNode> AddStage<TProcessor>(string name)
/// <param name="processor">The first processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddStage(Processor<TNode> processor, params Processor<TNode>[] others) =>
public PipelineBuilder<TNode> AddStage(Processor<TNode> processor, [InstantHandle] params IEnumerable<Processor<TNode>> others) =>
AddStage(b => b.Add(processor, others));

/// <summary>
Expand All @@ -60,7 +60,7 @@ public PipelineBuilder<TNode> AddStage(Processor<TNode> processor, params Proces
/// <param name="processor">The first processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddStage(string name, Processor<TNode> processor, params Processor<TNode>[] others) =>
public PipelineBuilder<TNode> AddStage(string name, Processor<TNode> processor, [InstantHandle] params IEnumerable<Processor<TNode>> others) =>
AddStage(b => b.WithName(name).Add(processor, others));

/// <summary>
Expand All @@ -85,7 +85,7 @@ public PipelineBuilder<TNode> AddParallelStage(Action<ParallelPipelineStageBuild
/// <param name="processor2">The second processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddParallelStage(UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, params UnorderedProcessor<TNode>[] others) =>
public PipelineBuilder<TNode> AddParallelStage(UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, [InstantHandle] params IEnumerable<UnorderedProcessor<TNode>> others) =>
AddParallelStage(b => b.Add(processor1).Add(processor2, others));

/// <summary>
Expand All @@ -97,7 +97,7 @@ public PipelineBuilder<TNode> AddParallelStage(UnorderedProcessor<TNode> process
/// <param name="processor2">The second processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddParallelStage(string name, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, params UnorderedProcessor<TNode>[] others) =>
public PipelineBuilder<TNode> AddParallelStage(string name, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, [InstantHandle] params IEnumerable<UnorderedProcessor<TNode>> others) =>
AddParallelStage(b => b.WithName(name).Add(processor1).Add(processor2, others));

/// <summary>
Expand All @@ -112,7 +112,7 @@ public PipelineBuilder<TNode> AddParallelStage(string name, UnorderedProcessor<T
/// <param name="processor2">The second processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddParallelStage(int maxDegreeOfParallelism, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, params UnorderedProcessor<TNode>[] others) =>
public PipelineBuilder<TNode> AddParallelStage(int maxDegreeOfParallelism, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, [InstantHandle] params IEnumerable<UnorderedProcessor<TNode>> others) =>
AddParallelStage(b => b.Add(processor1).Add(processor2, others).WithMaxDegreeOfParallelism(maxDegreeOfParallelism));

/// <summary>
Expand All @@ -128,7 +128,6 @@ public PipelineBuilder<TNode> AddParallelStage(int maxDegreeOfParallelism, Unord
/// <param name="processor2">The second processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public PipelineBuilder<TNode> AddParallelStage(string name, int maxDegreeOfParallelism, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2,
params UnorderedProcessor<TNode>[] others) =>
public PipelineBuilder<TNode> AddParallelStage(string name, int maxDegreeOfParallelism, UnorderedProcessor<TNode> processor1, UnorderedProcessor<TNode> processor2, [InstantHandle] params IEnumerable<UnorderedProcessor<TNode>> others) =>
AddParallelStage(b => b.WithName(name).Add(processor1).Add(processor2, others).WithMaxDegreeOfParallelism(maxDegreeOfParallelism));
}
2 changes: 1 addition & 1 deletion src/MrKWatkins.Ast/Processing/PipelineStageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TSelf Add<TConstructableProcessor>()
/// <param name="processor">The first processor to add.</param>
/// <param name="others">Other processors to add.</param>
/// <returns>The fluent builder.</returns>
public TSelf Add(TProcessor processor, params TProcessor[] others)
public TSelf Add(TProcessor processor, [InstantHandle] params IEnumerable<TProcessor> others)
{
Processors.Add(processor);
Processors.AddRange(others);
Expand Down
2 changes: 1 addition & 1 deletion src/MrKWatkins.Ast/PropertyNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected PropertyNode()
/// </summary>
/// <param name="children">The children to add.</param>
/// <exception cref="InvalidOperationException">If any of <see cref="Node{TNode}.Children" /> already have a <see cref="Node{TNode}.Parent" />.</exception>
protected PropertyNode([InstantHandle] IEnumerable<TNode> children)
protected PropertyNode([InstantHandle] params IEnumerable<TNode> children)
: base(children)
{
}
Expand Down

0 comments on commit dee9843

Please sign in to comment.