I would like to create an Attribute to put on properties.
The properties that will contains this attribute will execute another method after setting a new value.
For example:
[MethodExecute(Log)]
[MethodExecute(Save)]
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
Here I would like to activate two methods, one will log the change and the other will save it.
Thanks, Ronny
I believe you could do this in PostSharp. You'll need to specify the method name as a string unfortunately - there's no operator in C# to resolve a method name into MethodInfo
, although it's been proposed a few times.
You may need to move the attribute if you need the code to execute only after the setter (rather than the getter):
public string Name
{
get;
[MethodExecute("Log")] [MethodExecute("Save")] set;
}
(This uses an automatically implemented property for simplicity.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With