   [.net] Attributes
  Heyas Folks, I am pondering! Which leads me to you, because you have the answers!I would like to write an Attribute that hooks up a Property Set Method to an event. In other words:Every time the set method of a property, which has my attribute assigned to, is called i want to call an other method after the set method.In pseudo code something like this:class Foo{[MyNewAttribute(CallMe, AttributeEnum.SetOnly)]public Int32 Bar {get;set;}void CallMe(){}}Foo foo = new Foo();foo.Bar = 10;this should do something like this:- Execute the Bar-Set Method- Execute CallMe MethodDoes anyone know how to accomplish this?Any hint, link or help is appreciated!!!cherio Woltan   
  Could you not just call the function from the set (assuming C#)?class Foo{public Int32 Bar {get;set {CallMe();}}void CallMe(){}}   ;  Yes I could, but I would like to make use of the automatic property, so that I do not have to define a variable. Furthermore, the code would be much nicer to read and since I always wanted to understand what attributes do I figured this would be a good time.By the way, C# is assumed correctly ;)Any other hints?cherio Woltan   ;  In general, attributes do not add behaviour.  Instead, they really just mark up code to add metadata.If an attribute is going to cause behaviour, then some other piece of code needs to check for the attribute and then react to it.  For example, in your situation (if you do not want to modify the automatic property) you could create a proxy class:class FooProxy{    Foo _InnerFoo;    public FooProxy(Foo innerFoo)    {   _InnerFoo = innerFoo;    }    public Int32 Bar    {   get { return _InnerFoo.Bar; }   set   {   _InnerFoo.Bar = value;   //Check for attribute and call method here   }    }}As you can tell, this involves a lot of repetition to get this done.  What you really want is to either not use the automatic property, or to upgrade to using Aspect Orient Programming (AOP).  If you want to do the second, I would suggest looking at Spring.Net AOP.  Using it, you will be able to automatically build these proxies at runtime just by writing a template for how to handle your attribute.Honestly though, its a lot of work compared to just not using an automatic property.   ;PostSharp has this functionality.I use it for implementing INotifyProperty changed.   ;  Thx ChaosEngine,this is exaclty what I was looking for! This community rocks!!!cherio Woltan   