Skip to content

Add Context to DefaultProviderAttribute#51

Open
MikeJansen wants to merge 1 commit into
adrianaisemberg:masterfrom
MikeJansen:master
Open

Add Context to DefaultProviderAttribute#51
MikeJansen wants to merge 1 commit into
adrianaisemberg:masterfrom
MikeJansen:master

Conversation

@MikeJansen

Copy link
Copy Markdown

New Context property for DefaultProviderAttribute which gets passed on
to new Context property on DefaultProvider abstract class.

I added this so that I could determine which property the DefaultProvider was being invoked on. I could not determine that from the VerbExecutionContext during DefaultProvider.GetDefault(). Another way could be to add a Parameter property to the VerbExecutionContext but this way seemed more flexible.

Now I can use a single DefaultProvider-derived class to service many different properties. In my specific application, I have a verb to set defaults for other verb/parameter combinations and the my DefaultProvider checks for a saved default if the parameter isn't supplied on the command line.

Example attribute usage:

[DefaultProvider(typeof(ProfileDefaultProvider), "chatId")]

Example DefaultProvider derived class:

public class ProfileDefaultProvider : DefaultProvider
{
public override object GetDefault(VerbExecutionContext context)
{
string verb = context.Method.MethodInfo.Name;
string key = Context;
return Program.ProfileData.GetVerbData(verb, key);
}
}

New Context property for DefaultProviderAttribute which gets passed on
to new Context property on DefaultProvider abstract class.

Example attribute usage:

[DefaultProvider(typeof(ProfileDefaultProvider), "chatId")]

Example DefaultProvider derived class:

public class ProfileDefaultProvider : DefaultProvider
{
   public override object GetDefault(VerbExecutionContext context)
   {
      string verb = context.Method.MethodInfo.Name;
      string key = Context;
      return Program.ProfileData.GetVerbData(verb, key);
   }
}
@MikeJansen

Copy link
Copy Markdown
Author

It doesn't look like you are actively developing this, but just wanted to pass on that I have been using CLAP for years and IMO it's still the best command line lib out there for .NET that I have run into. I even use it for a command parser in a chat application we have developed.

@adrianaisemberg

Copy link
Copy Markdown
Owner

@MikeJansen that's true.
Unfortunately I am not actively involved in this project anymore.

Thank you for your feedback. I really appreciate it and seeing that CLAP is still being used after so many years means a lot to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants