64 lines
1.1 KiB
Plaintext
64 lines
1.1 KiB
Plaintext
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
|
|
|
|
[source,csharp]
|
|
----
|
|
using System;
|
|
|
|
namespace MyLibrary
|
|
{
|
|
public class Foo
|
|
{
|
|
public DateTime Date
|
|
{
|
|
get { return DateTime.Today; }
|
|
}
|
|
|
|
public string GetDate() // Noncompliant
|
|
{
|
|
return this.Date.ToString();
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,csharp]
|
|
----
|
|
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)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|