I have a class library that wraps the command line client for Mercurial.
My intention is to implement support for all the built-in commands, but in addition to those, there's a ton of extensions out there.
So I need to make my library extendable in the sense that both others and I can add support for extensions. I plan on adding support for some of the more popular and typical extensions (at the very least quite a few of those that come bundled with Mercurial), but I still want to be able to extend it from the outside.
At the moment, the syntax of a command look like this:
Repo.Execute(new CommitCommand
{
Message = "Your commit message",
AddRemove = true,
});
This, however, doesn't lend itself very easily to extensions, without the programmer feeling that the extension is just a tacked on part.
For instance, let's assume I expose a public collection of additional command line arguments, to that I could manually do this:
var cmd = new CommitCommand
{
Message = "Your commit message",
AddRemove = true,
};
cmd.Arguments.Add("--my-commit-extension");
Repo.Execute(cmd);
There seems to be no easy way for me to get that additional extension added in such a way that it can be set as part of the object initializer.
I've been thinking of adding, or perhaps switching, to a fluent interface syntax. In this case, you could write something like this:
Repo.Execute(new CommitCommand()
.Message("Your commit message")
.AddRemove()
.MyCommitExtension());
However, I see people don't like fluent interfaces, they feel they become too chatty.
What other options do I have?
What I want, basically:
- One common syntax style
- For both built-in things
- As well as extensions added by users of my library
I envision that users of my library would extend it by adding new classes, and extension methods to get intellisense support, but extension methods can't be used in object initializers, which means that all extensions look like some afterthought. That's not what I want.
Any ideas are welcome.