pdowling
November 23rd, 2006, 03:37 PM
Hi
I want to create a class whose constructor takes a format pattern as the first argument and then potentially infinite format arguments. e.g.
public class ZenException : Exception
{
public ZenException()
{
}
public ZenException(string message)
: base(message)
{
}
public ZenException(string format, object arg0)
: base(string.Format(format, arg0))
{
}
public ZenException(string format, object arg0, object arg1)
: base(string.Format(format, arg0, arg1))
{
}
etc.....
}
But I don't want to write a constructor for each possible number of arguments. The .NET string.Format() method itself can take virtually any number of arguments, yet when I used Reflector to see how it did this it only showed a maximum of 3 args. Is there some way of allowing a constructor to take any number of arguments without having to write a constructor for each quantity?
Cheers for any help.
I want to create a class whose constructor takes a format pattern as the first argument and then potentially infinite format arguments. e.g.
public class ZenException : Exception
{
public ZenException()
{
}
public ZenException(string message)
: base(message)
{
}
public ZenException(string format, object arg0)
: base(string.Format(format, arg0))
{
}
public ZenException(string format, object arg0, object arg1)
: base(string.Format(format, arg0, arg1))
{
}
etc.....
}
But I don't want to write a constructor for each possible number of arguments. The .NET string.Format() method itself can take virtually any number of arguments, yet when I used Reflector to see how it did this it only showed a maximum of 3 args. Is there some way of allowing a constructor to take any number of arguments without having to write a constructor for each quantity?
Cheers for any help.