I am new to AOP and post sharp (2.1.0.0). I have been experimenting with property/method interception and am able to write inteceptor aspects for classes which I have written.
My goal is to not have lists with any logic in them before compile time.
An example of what I want to achieve is:
public class Foo
{
//Implementation should throw an exception if more than 1 string added.
public List<string> MyList { get; set; }
}
One thing I am not sure about are lists. I want to be able to run some validation when either Add() or Remove() is called on a list. I think I can do this if I wrap the list in my own custom list class and decorate the class with the aspect attribute.
I know I can accomplish this using my own custom list and do something clever in my own implementations of Add/Remove - but this is what I would prefer to avoid if possible.
Is there any other (or a better) way of intercepting these methods - specifically using post sharp?
There isn't a collection changed event for a generic List in .NET. I know you don't want to hear this, but you either need to wrap List or you need to create a class that implements IList.