Skip to content

Commit

Permalink
Use with syntax to clone
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk committed Sep 25, 2024
1 parent 419cf3f commit 1b590c1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
8 changes: 0 additions & 8 deletions src/NATS.Client.JetStream/Models/StreamConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,4 @@ internal StreamConfig()
[System.Text.Json.Serialization.JsonPropertyName("metadata")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public IDictionary<string, string>? Metadata { get; set; }

/// <summary>
/// Creates a shallow copy of the current StreamConfig instance using the MemberwiseClone method.
/// </summary>
/// <return>
/// A shallow copy of the current StreamConfig.
/// </return>
public StreamConfig ShallowCopy() => (StreamConfig)MemberwiseClone();
}
8 changes: 0 additions & 8 deletions src/NATS.Client.JetStream/Models/StreamSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,4 @@ public record StreamSource
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
public string? Domain { get; set; }

/// <summary>
/// Creates a shallow copy of the current StreamSource instance using the MemberwiseClone method.
/// </summary>
/// <return>
/// A shallow copy of the current StreamSource.
/// </return>
public StreamSource ShallowCopy() => (StreamSource)MemberwiseClone();
}
6 changes: 3 additions & 3 deletions src/NATS.Client.JetStream/NatsJSContext.Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public async ValueTask<INatsJSStream> CreateStreamAsync(
ThrowIfInvalidStreamName(config.Name, nameof(config.Name));

// keep caller's config intact.
config = config.ShallowCopy();
config = config with { };

// If we have a mirror and an external domain, convert to ext.APIPrefix.
if (config.Mirror != null && !string.IsNullOrEmpty(config.Mirror.Domain))
{
config.Mirror = config.Mirror.ShallowCopy();
config.Mirror = config.Mirror with { };
ConvertDomain(config.Mirror);
}

Expand All @@ -39,7 +39,7 @@ public async ValueTask<INatsJSStream> CreateStreamAsync(
{
if (!string.IsNullOrEmpty(ss.Domain))
{
var remappedDomainSource = ss.ShallowCopy();
var remappedDomainSource = ss with { };
ConvertDomain(remappedDomainSource);
sources.Add(remappedDomainSource);
}
Expand Down
10 changes: 6 additions & 4 deletions src/NATS.Client.KeyValueStore/NatsKVContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ private static StreamConfig CreateStreamConfig(NatsKVConfig config)

if (config.Mirror != null)
{
mirror = config.Mirror.ShallowCopy();
mirror.Name = config.Mirror.Name.StartsWith(KvStreamNamePrefix)
? config.Mirror.Name
: BucketToStream(config.Mirror.Name);
mirror = config.Mirror with
{
Name = config.Mirror.Name.StartsWith(KvStreamNamePrefix)
? config.Mirror.Name
: BucketToStream(config.Mirror.Name),
};
mirrorDirect = true;
subjects = default;
sources = default;
Expand Down

0 comments on commit 1b590c1

Please sign in to comment.