Friday, May 6, 2011

C# - Custom Attributes

Hi!

I want to log all calls to all class methods with a specific attribute. How would i do this?

This is what I have so far:

class ExecutionLogAttribute : Attribute
{
}

public class Human
{
    private Int32 age;

    [ExecutionLog]
    public void HaveBirthday()
    {
        age++;
    }
}

What would now be the best way to log all calls to HaveBirthday?

From stackoverflow
  • Simple answer: PostSharp. More complex one: Spring.NET or custom AOP (this is what you need: Aspect-Oriented Programming) implementation using ContextBoundObject.

    alexn : Thanks for the response. I'm going to look in to that!

0 comments:

Post a Comment