Not sure if it good solution, but you can use MrAdvice
It allo add decorators to property setter.
I tested it a little, and it's works.
public class Person : INotifyPropertyChanged {
public string GivenNames { get; set; }
[ SetWrapper( nameof(SomeTest), nameof(SomeTest1) ) ]
public string FamilyName { get; set; }
public string FullName => $"{GivenNames} {FamilyName}";
private void SomeTest( ) {
Console.WriteLine( nameof(SomeTest) );
}
private static void SomeTest1( ) {
Console.WriteLine( nameof(SomeTest1) );
}
public event PropertyChangedEventHandler PropertyChanged;
}
and implementation for SetWrapper attribute
public class SetWrapper : Attribute, IMethodAdvice {
private readonly string[] _addingMetod;
public SetWrapper( params string[] addingMethods ) {
_addingMetod = addingMethods;
}
public void Advise( MethodAdviceContext context ) {
context.Proceed( );
foreach( var methodName in this._addingMetod ) {
InvokeMethod( context, methodName );
}
// do other things here
}
private static void InvokeMethod( MethodAdviceContext context, string methodName ) {
if( context.TargetMethod.Name.StartsWith( "set_" ) && !string.IsNullOrEmpty( methodName ) ) {
var method = context.TargetMethod?.ReflectedType?.GetMethod( methodName
, BindingFlags.Public
| BindingFlags.Static
| BindingFlags.NonPublic
| BindingFlags.Instance );
if( method != null ) {
if( method.IsStatic ) {
method.Invoke( null, Array.Empty<object>( ) );
} else {
method.Invoke( context.Target, Array.Empty<object>( ) );
}
}
}
}}