Is there an app or website where I can input parameter info (types and variable names), their defaults, and have it generate all the combinations of method overloads?
I have a class where the constructor can take in five parameters of different types. The parameters get mapped to properties, none of which have public setters. Each parameter has a default value.
I want my class to have overloaded constructors for all the various combinations of the parameters (ranging from no parameters to any and all combinations of the five parameters). To make it more confusing, one of the parameters can be passed in as a specific type or as a string, and I want the various combinations of overloads to take that into consideration.
Update:
I agree this design may not be the best. The class in question is one I’m using in a similar fashion to the PropertyMetadata class of WPF’s DependencyProperty. A value is assigned for the property backing, and a new instance of the metadata class is passed in at that time. It’s forcing my hand to create this cascading series of constructor overloads. Example:
private ModelProperty<UserModel, string> firstNameProperty =
RegisterProperty(p => p.FirstName, new ModelPropertyMetadata(**** lots of overloads here ****));
public string FirstName
{
get { return GetValue(firstNameProperty); }
set { SetValue(firstNameProperty, value); }
}
Maybe that’s not the best design. I could possibly extend ModelPropertyMetadata to new classes which describe specific overloads, but that just seems like its pushing the problem somewhere else. Any thoughts on how to make this design better?
Take a look at optional parameters – these should help you avoid multiple overloads and still provide multiple ways to call a constructor. This is a .NET 4.0 feature.