rspec/rules/S4059/csharp/rule.adoc

74 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Properties and Get method should have names that makes them clearly distinguishable.
This rule raises an issue when the name of a public or protected member starts with 'Get' and otherwise matches the name of a public or protected property.
=== 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 DateTime Date
{
get { return DateTime.Today; }
}
public string GetDate() // Noncompliant
{
return this.Date.ToString();
}
}
}
----
=== 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;
namespace MyLibrary
{
public class Foo
{
public DateTime Date
{
get { return DateTime.Today; }
}
public string GetDateAsString()
{
return this.Date.ToString();
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Change either the name of the property "XXX" or the name of the method "GetXXX" to make them distinguishable.
=== Highlighting
Primary: Property declaration
Secondary: Getxxx method
endif::env-github,rspecator-view[]