2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
A method using the ``++VarArgs++`` calling convention is not Common Language Specification (CLS) compliant and might not be accessible across programming languages, while the ``++params++`` keyword works the same way and is CLS compliant.
This rule raises an issue when a ``++public++`` or ``++protected++`` type contains a ``++public++`` or ``++protected++`` method that uses the ``++VarArgs++`` calling convention.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
public class Foo
{
public void Bar(__arglist) // Noncompliant
{
ArgIterator argumentIterator = new ArgIterator(__arglist);
for(int i = 0; i < argumentIterator.GetRemainingCount(); i++)
{
Console.WriteLine(
__refvalue(argumentIterator.GetNextArg(), string));
}
}
}
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
[assembly: CLSCompliant(true)]
namespace MyLibrary
{
public class Foo
{
public void Bar(params string[] wordList)
{
for(int i = 0; i < wordList.Length; i++)
{
Console.WriteLine(wordList[i]);
}
}
}
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Exceptions
2021-04-28 16:49:39 +02:00
Interop methods using ``++VarArgs++`` calling convention do not raise an issue.
2023-05-25 14:18:12 +02:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
[DllImport("msvcrt40.dll")]
public static extern int printf(string format, __arglist); // Compliant
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Use the "params" keyword instead of "__arglist".
=== Highlighting
Method declaration
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]