From 3eb4880f6b689632e54c5af70f4e29b5e0bc4bc0 Mon Sep 17 00:00:00 2001 From: Martin Strecker Date: Tue, 22 Oct 2024 16:20:22 +0200 Subject: [PATCH] Add diff and extend examples --- rules/S3878/csharp/rule.adoc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/rules/S3878/csharp/rule.adoc b/rules/S3878/csharp/rule.adoc index 57c84045847..7f15c8e22ee 100644 --- a/rules/S3878/csharp/rule.adoc +++ b/rules/S3878/csharp/rule.adoc @@ -8,37 +8,47 @@ Creating an array or using a collection expression solely for the purpose of pas ==== Noncompliant code example -[source,csharp] +[source,csharp,diff-id=1,diff-type=noncompliant] ---- public void Base() { - Method(new string[] { "s1", "s2" }); // Noncompliant: unnecessary - Method(new string[] { }); // Noncompliant - Method(["s3", "s4"]); // Noncompliant - Method(new string[12]); // Compliant + Method(new string[] { "s1", "s2" }); // Noncompliant: resolves to string[] overload + Method(new string[] { }); // Noncompliant: resolves to string[] overload + Method(["s3", "s4"]); // Noncompliant: resolves to ReadOnlySpan overload + Method(new string[12]); // Compliant: resolves to string[] overload } -==== Compliant solution + public void Method(params string[] args) { // ... } + +public void Method(params ReadOnlySpan args) // C# 13 params collections +{ + // C# 13 params collection +} ---- === Compliant solution -[source,csharp] +[source,csharp,diff-id=1,diff-type=compliant] ---- public void Base() { - Method("s1", "s2"); - Method(); - Method("s3", "s4"); - Method(new string[12]); + Method("s1", "s2"); // resolves to ReadOnlySpan overload + Method(); // resolves to ReadOnlySpan overload + Method("s3", "s4"); // resolves to ReadOnlySpan overload + Method(new string[12]); // resolves to string[] overload } public void Method(params string[] args) { - // ... + // .. +} + +public void Method(params ReadOnlySpan args) // C# 13 params collections +{ + // .. } ----