2021-06-03 09:05:38 +02:00
=== on 16 Dec 2014, 20:40:12 Ann Campbell wrote:
2021-06-02 20:44:38 +02:00
\[~dinesh.bolkensteyn] what about a property which has logic in one of the methods but not the other?
2021-06-03 09:05:38 +02:00
=== on 17 Dec 2014, 06:38:06 Dinesh Bolkensteyn wrote:
2021-06-02 20:44:38 +02:00
I've tested that yesterday [~ann.campbell.2], it's not possible: There is no way to explicitly access the implicit backing field, so there is no way to add any logic to an auto-property.
2021-06-03 09:05:38 +02:00
=== on 17 Dec 2014, 13:01:10 Ann Campbell wrote:
2021-06-02 20:44:38 +02:00
\[~dinesh.bolkensteyn] I'm not sure I was clear. I'm talking about something like this:
----
private string _make;
public string Make // Noncompliant
{
get { return _make; }
set
{
// do stuff to value...
_make = value;
}
}
----
2021-06-03 09:05:38 +02:00
=== on 17 Dec 2014, 13:05:37 Dinesh Bolkensteyn wrote:
2021-06-02 20:44:38 +02:00
So you actually mean:
----
private string _make;
public string Make
{
get { return _make; }
set
{
if (value == null)
{
throw new SomeException();
}
_make = value;
}
}
----
That is perfectly valid and compliant. There is nothing that can be improved there.