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 method arguments to IAdvice.Begin #14

Open
VanKrock opened this issue Aug 27, 2019 · 3 comments
Open

Add method arguments to IAdvice.Begin #14

VanKrock opened this issue Aug 27, 2019 · 3 comments

Comments

@VanKrock
Copy link

IAdvice.Begin doesn't have method arguments

Arguments needed for templates, such as

[Log("My method: {value}")]
void MyMethod(string value);

IAdvice.Begin can be

void Begin(object[] args);
@Puresharper
Copy link
Owner

Puresharper commented Aug 30, 2019

Hi,

You have to implements method Argument(T value) and store value in a field.
exemple

public Advice1 : IAdvice
{
    private readonly List<object> arguments;

    public void Argument<T>(ref T value)
    {
        this.arguments.Add(value);
    }

    public void Begin()
    {
        this.arguments... //here list of arguments?
    }
    ...
}

@VanKrock
Copy link
Author

VanKrock commented Aug 30, 2019

It's will work if I call my method twice?

@Puresharper
Copy link
Owner

Puresharper commented Sep 2, 2019

Yes, it depends how you create your "aspect/advisor"

public class Logging : Aspect
{
    override public IEnumerable<Advisor> Manage(MethodBase method)
    {
        yield return Advice
            .For(method)
            .Around(() => new Log(method));
    }
}

here the delegate to create 'Log Advice' is called each time you call your method. This is what I recommend to manage method call contextual datas. In this case you can even specialize an advice depending on target method.

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

No branches or pull requests

2 participants