Comment décorer une classe à l'execution ?
Je suis en train de réaliser une dll de mapping O/R, et comme je suis vraiment fainéant quand il s'agit de réécrire 12000 fois la même chose, j'aimerais que cette dll se charge de ça à ma place.
Je pense ici précisément à l'interface INotifyPropertyChanged.
Voici un petit exemple de ce que je souhaite obtenir...
Soit la classe MyClass, que j'aurais écrite ainsi :
Code:
1 2 3 4 5 6 7 8
| class MyClass
{
private int _myInt;
public int MyInt { get { return _myInt; } set { _myInt = value; } }
public MyClass(int myInt) { _myInt = myInt; }
} |
Et qui lors de sa compilation JIT se retrouvera ainsi :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class MyClass : INotifyPropertyChanged
{
private int _myInt;
public int MyInt { get { return _myInt; } set { _myInt = value; OnPropertyChanged(this,new PropertyChangedEventArgs("MyInt")); } }
public MyClass(int myInt) { _myInt = myInt; }
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(object sender,PropertyChangedEventArgs e){
if(PropertyChanged!=null)
PropertyChanged(sender,e);
}
} |
Alors je ne sais pas si c'est possible.
J'ai entendu parler de réécriture de méthodes, de profiling, d'AOP weaving...