In an app where a port number is set, I want to restrict the values assignable to the port number to those between 49152 and 65535 (inclusive).
I wrote some test methods that test that anything outside of this range causes the test to fail. They do fail (as expected, as the code does not yet take that into account).
So my question is: what is the best place to put the code that forces an invalid value to a valid value - here:
public int Port
{
get
{
return port;
}
set
{
port = value;
}
}
such as:
public int Port
{
get
{
return port;
}
set
{
if ((value < 49152) || (value > 65535))
{
value = 55555;
}
port = value;
}
}
...or somewhere else?