-
Notifications
You must be signed in to change notification settings - Fork 113
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
New Ingercept call within method
Advice Type
#102
Comments
Hi, if you mean assembly-wide propagation with filter it is done like that: using AspectInjector.Broker;
using ConsoleApp2;
using System;
using System.Reflection;
[assembly: LogTextMembers]
namespace ConsoleApp2
{
class Program
{
public Program() { }
public string Text { get; set; }
static void Main(string[] args)
{
var prog = new Program();
prog.Text = "Hello World!";
Console.WriteLine(prog.Text);
}
}
[Aspect(Scope.Global)]
[Injection(typeof(LogTextMembers), Propagation = PropagateTo.Everything, PropagationFilter ="Text")]
class LogTextMembers : Attribute
{
[Advice(Kind.Before)]
public void LogCall(
[Argument(Source.Metadata)] MethodBase info,
[Argument(Source.Arguments)] object[] args
)
{
Console.WriteLine($"Calling {info.Name}({string.Join(',', args)})");
}
}
} Note that PropagationFilter is full featured regex filter |
thank you, that is i am need. |
in your example calling "Console.WriteLine(prog.Text);" not logged, it possible intercept call all functions? |
Hi static void Main(string[] args)
{
var prog = new Program();
prog.Text = "Hello World!";
LogCall(()=>Console.WriteLine(prog.Text));
} So you can use LogCall to do what ever you want with function call. If this is the case, unfortunately this is not how aspect-injector currently works. It does not inject into the call site. It injects into the call's target. In this example the injection would be done not in the Main() method body, but in Console.WriteLine method body, which is (almost) impossible. So by now, you can only intercept function written by you (the ones you're compiling). However this good candidate for enhancement. I'll need to think how this can be implemented. Stay tuned :) |
Ingercept call within method
Advice Type
hello,
Does have support intercept runs method from foreign libs?
example from postsharp (https://www.postsharp.net/logging):
[assembly: Log( AttributePriority = 3, AttributeTargetAssemblies = "mscorlib" AttributeTargetTypes = "Microsoft.Win32.Registry*" )]
It needs for customize logging assert libs: https://github.com/allure-framework/allure-java/blob/f50f4b9ecd2d37bf04fca0193548ad954f715118/allure-assertj/src/main/java/io/qameta/allure/assertj/AllureAspectJ.java#L58
The text was updated successfully, but these errors were encountered: