In order to have a Set
method like you're after it would have to have a parameter for each option you wanted to set, which will probably get unwieldy after time,
You can opt for a fluent interface which should give you want you want. For example:
class Options
{
Options Option1(string value)
{
m_Option1 = value;
return this;
}
Options Option2(int value)
{
m_Option2 = value;
return this;
}
}
Now AddString
would look like this:
AddString(options = > options.Option1("A String").Option2(1)));
And the implementation of AddString
would look like this:
public void AddString(Action<Options> optionConfig)
{
var options = new Options();
optionConfig(options);
// rest of method
}
Alternatively you could have the caller create the Options
instance. This would allow them to set the properties directly:
class Options
{
public string Option1{get;set;}
public int Option2{get;set;}
}
And now the caller can say:
AddString(() = > new Options{Option1="A String", Option2=1});
Where AddString
looks like this:
public AddString(Func<Options> optionsCreator)
{
Options options = optionsCreator();
// rest of method
}