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

PointcutSelector Attribute #90

Open
Kahbazi opened this issue Dec 27, 2016 · 2 comments
Open

PointcutSelector Attribute #90

Kahbazi opened this issue Dec 27, 2016 · 2 comments

Comments

@Kahbazi
Copy link

Kahbazi commented Dec 27, 2016

Let's say we have a code like this :

[assembly: LogAdvice]

[IncludePointcut("*Add")]
public class LogAdviceAttribute : Attribute, IMethodAsyncAdvice
{
    public async Task Advise(MethodAsyncAdviceContext context)
    {
        Console.WriteLint("Entry");
        await context.ProceedAsync();
        Console.WriteLint("Exit");             
    }
}

If I understand correctly when we build the project, Weaver will check all methods in assembly and if their full name matches "*Add" it will advice it.

This is good, but I need more than just name checking for advice. for example I want to advice all private methods that their output is int.

This is what I have in my mind :

public interface IPointcutSelector
{
    bool ShouldAdvice(MethodInfo methodInfo);
}

public class PointcutSelectorAttribute : Attribute, IPointcutSelector
{
    public bool ShouldAdvice(MethodInfo methodInfo)
    {
        return methodInfo.IsPrivate && methodInfo.ReturnType == typeof(int);
    }
}

Can we have this? :)

@picrap
Copy link
Member

picrap commented Dec 27, 2016

Currently, not. This is a recurring problem I have, where Mr. Advice weaver would need to load the weaved assembly, regardless the platform. Mr. Advice weaver uses .NET framework 4.5, but since you can weave assemblies for many platforms (Silverlight, or anything from .NET standard 1.5), the weaver can not load assembly from any other platform, so I need to solve this in order to allow such extensibility. Any idea welcome 😉

picrap added a commit that referenced this issue Dec 27, 2016
@picrap picrap closed this as completed Dec 27, 2016
@picrap picrap reopened this Dec 28, 2016
@picrap
Copy link
Member

picrap commented Mar 10, 2017

This probably can be done once the number of targets is reduced to two, which are .NET framework 4.0 and .NET Standard 2.0 (if this one is supported by other frameworks).

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

No branches or pull requests

2 participants