C#C
C#3y ago
skyslide22

❔ Python Decorators in C# ??? How do i intercept method calls with attributes?

Is is possible to intercept/prevent a method call in c# with attributes? i was thinking about something like python decorators, which can decide what happens with the method call, args and return value

[ThrowIfIdMatches("id", 69)]
public string MyMethod(int id)
{
  return "my id is " + id
}

that should throw a ValueError if the
id
parameter is 69, for example
Was this page helpful?