I have a static class ArgumentHelper
which can check for example: ArgumentHelper.NotNull(instance, "instance")
. But it works for some standard built-in .net framework classes, if I implement my own classes, I cannot put checking in ArgumentHelper, because this class will be too big.
So I was thinking, and I found a solution: I will make a nested static class in every new made custom class:
public class MyClass
{
private int x;
public MyClass (int x)
{
if (x < 0) throw new ArgumentOutOfRangeException (...);
this.x = x;
}
public static class Arg
{
public static void NotZero (MyClass mc)
{
if (mc.x == 0) throw ....
}
}
}
So now:
public void myMethod (MyClass mc)
{
MyClass.Arg.NotZero (mc); // will throw excweption if x == 0
do some stuff
}
Is it a good idea, or you have different approach?