保持在屬性我有有一個屬性,又具有Func<object, object>
屬性的功能,我想在該屬性更改執行的功能(使用更新後的資產價值爲in T
)。這樣做最光滑的方法是什麼?執行後性能變化
注:我知道屬性是靜態並沒有被設計成執行在他們的受讓人改變/ invocaction的事實。我只需要儘可能接近我創建的原型。
一些代碼:
using System;
using System.Windows;
namespace AnnotatedBinding
{
public class AnnotatedPropertyAttribute: Attribute
{
// static
public AnnotatedPropertyAttribute(Func<object, object> evaluator)
{
Evaluator = evaluator;
}
public Func<object, object> Evaluator
{
get; private set;
}
}
public class Test
{
[AnnotatedProperty(Test.TestEvaluator)] // not compiling!, guess it's fixable by passing in a member info and then calling Reflection Invoke?
public string TestProperty
{
get; set;
}
public static Func<object, object> TestEvaluator = (x) => MessageBox.Show(x.ToString());
}
public class Shell
{
public void Run()
{
var test = new Test();
test.TestProperty = "blah";// I want my message box here
test.TestProperty = "blah";// and I don't want it here
}
}
}
愛情http://www.postsharp.net/ – user1514042