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

Fix discovery injection into setter or getter directly #79

Closed
paxhujing opened this issue Dec 29, 2018 · 3 comments
Closed

Fix discovery injection into setter or getter directly #79

paxhujing opened this issue Dec 29, 2018 · 3 comments
Labels

Comments

@paxhujing
Copy link

paxhujing commented Dec 29, 2018

 [Aspect(Scope.Global)]
    [Injection(typeof(WriteConsoleAttribute))]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class WriteConsoleAttribute : Attribute
    {
        [Advice(Kind.After, Targets = Target.Setter)]
        public void WriteLine([Argument(Source.Arguments)] Object[] args)
        {
            Console.WriteLine(String.Join(';', args));
        }
    }
private Int32 _lineCount;
        public Int32 LineCount
        {
            get => _lineCount;
            [WriteConsole]
            set
            {
                if (_lineCount != value)
                {
                    _lineCount = value;
                    LineBet = value * BetPerLine;
                }
            }
        }
@pamidur
Copy link
Owner

pamidur commented Dec 29, 2018

In this case I assume (I can't check right now) it treats setter as a method. So you can either

  1. Mark whole property LineCount with WriteConsoleAttribute
    Or
  2. Make advice target = Method.

Anyway, it is workaround. This should be fixed. Thanks for the report

@pamidur pamidur changed the title Why injection property doesn't work? Fix discovery invection into setter or getter directly Jan 3, 2019
@pamidur pamidur added the bug label Jan 3, 2019
pamidur added a commit that referenced this issue Jan 3, 2019
@pamidur
Copy link
Owner

pamidur commented Jan 3, 2019

fixed in 2.0.1

@pamidur pamidur closed this as completed Jan 3, 2019
@pamidur
Copy link
Owner

pamidur commented Jan 3, 2019

setter and getter are methods, so if you want to inject like this

            [WriteConsole]
            set

you need to have your advice target set to Method

[Advice(Kind.After, Targets = Target.Method)]

@pamidur pamidur changed the title Fix discovery invection into setter or getter directly Fix discovery injection into setter or getter directly Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants