[AOP] with a new keyword #7628
Answered
by
srburton
srburton
asked this question in
Language Ideas
-
Hi, my name is Renato Burton, I have a new idea and I want to propose it for the discussion. My idea is create a new keyword with name namespace Aop
{
public aspect class Program
{
[Event]
static string Main(string[] args)
{
Console.WriteLine("Main method executed!");
return "Logged!!!";
}
[Event]
static void OtherMain(string[] args)
{
Console.WriteLine("OtherMain method executed!");
}
}
public aspect class Event: Attribute
{
public void Handle(Type type, object[] args)
{
if (type.IsClass)
{
Console.WriteLine("The aspect intercept is class");
}
else (type.isMethod)
{
Console.WriteLine($"The method [name_method] with a arg: ${args[0]}");
}
}
// When have return the method
public void Handle(Type type, dynamic value)
{
if(type.isMethod && value!= null)
{
Console.WriteLine($"The method [name_method] return : ${value}");
}
else if ( value == null){
Console.WriteLine($"The method [name_method] return : null");
}
}
}
} RunProgram.Main("I love c#")
Program.OtherMain("I don't love c#") Output
|
Beta Was this translation helpful? Give feedback.
Answered by
srburton
Oct 25, 2023
Replies: 1 comment 1 reply
-
Check out: https://www.postsharp.net/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@HaloFour Yes, I saw that. But something in the core csharp i think is more performative.