public class Foo { void Repaint(int backColor, int foreColor) { } }
Perform argument validation for every public or protected (family) method and property setter, and throw meaningful exceptions to the developer. The System.ArgumentException exception is used in these cases.
class Foo { public int Count { get { return count; } set { if (count < 0 || count >= MaxValue) throw new ArgumentOutOfRangeException(Sys.GetString("InvalidArgument", "value", count.ToString()); } } public void Select(int start, int end) { if (start < 0) throw new ArgumentException(Sys.GetString("InvalidArgument", "start", start.ToString())); if (end < 0) throw new ArgumentException(Sys.GetString("InvalidArgument", "end", end.ToString())); } }
Note that the actual checking does not necessarily have to happen in the public/protected (family) method itself (e.g. it could happen at a lower level in some private routines). The bottom line is that the entire surface area that is exposed to developers checks for valid arguments.