rspec/rules/S927/csharp/rule.adoc

121 lines
2.5 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
The name of a parameter in an externally visible. This rule raises an issue when method override does not match the name of the parameter in the base declaration of the method, or the name of the parameter in the interface declaration of the method or the name of any other ``++partial++`` definition.
2020-06-30 12:50:59 +02:00
=== Noncompliant code example
2020-06-30 12:50:59 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:50:59 +02:00
----
partial class Point
{
partial void MoveVertically(int z);
}
partial class Point
{
int x = 0;
int y = 0;
int z = 0;
partial void MoveVertically(int y) // Noncompliant
{
this.y = y;
}
}
interface IFoo
{
void Bar(int i);
}
class Foo : IFoo
{
void Bar(int z) // Noncompliant, parameter name should be i
{
}
}
----
=== Compliant solution
2020-06-30 12:50:59 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:50:59 +02:00
----
partial class Point
{
partial void MoveVertically(int z);
}
partial class Point
{
int x = 0;
int y = 0;
int z = 0;
partial void MoveVertically(int z)
{
this.z = z;
}
}
interface IFoo
{
void Bar(int i);
}
class Foo : IFoo
{
void Bar(int i)
{
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 13 May 2015, 19:41:54 Ann Campbell wrote:
\[~tamas.vajk], please provide R# id if one exists
=== on 13 May 2015, 19:42:01 Ann Campbell wrote:
consulted \https://msdn.microsoft.com/en-us/library/vstudio/6b0scde8%28v=vs.110%29.aspx
=== on 13 May 2015, 19:42:23 Ann Campbell wrote:
\[~evgeny.mandrikov] note that this seemed familiar to me, but I couldn't find a relevant C-Family rule.
=== on 13 May 2015, 21:03:05 Evgeny Mandrikov wrote:
\[~ann.campbell.2] I suppose that you have in mind RSPEC-927
=== on 14 May 2015, 11:12:14 Ann Campbell wrote:
Thanks [~evgeny.mandrikov]
=== on 22 May 2015, 09:44:25 Tamas Vajk wrote:
Could you run through it one more time? There were minor modifications in the sample code.
=== on 22 May 2015, 12:14:06 Ann Campbell wrote:
\[~tamas.vajk] I'm not sure why you swapped the parameter order. I feel like reversing the names is a better illustration of the confusion that could result in param names that don't match...?
=== on 22 May 2015, 12:48:42 Tamas Vajk wrote:
\[~ann.campbell.2] I changed it because ``++yk++`` was not used in the method body, so it already just looked like a typo.
I've changed the sample code.
=== on 22 May 2015, 14:35:14 Ann Campbell wrote:
Thanks [~tamas.vajk]. Looks good
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]