Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Context to DefaultProviderAttribute #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MikeJansen
Copy link

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
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
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