我希望在绑定场景中执行繁重操作时使用标志在 Silverlight 中实现挂起和恢复绑定。
我的问题是在现有项目中使用了重绑定绘图机制。
在 silverlight 中使用 UpdateTrigger() 我们可以实现手动触发绑定。
但它是一个巨大的产品。无法更新和查找手动触发绑定等的位置并更改项目。
因此,我们计划使用 Microsoft Unity 通过在重载绘图操作上使用标志挂起和恢复绑定来快速修复。这可能是在绘制绑定对象时对当前性能问题的快速修复。
我希望在为不同类型的属性设置值之前检查一个布尔标志?在属性设置器之前,我搜索了很多并且厌倦了找到拦截。但是没有找到方法。还在战斗。这是我的确切要求。
有人帮忙吗?
添加了示例代码尝试,
//Empty Interface may be used in interface interception, not sure.
public interface ISetter
{
}
//Implementation of ISetter, this type needs to be intercepted while setting the FirstName //property
public class Man : ISetter
{
private string firstName;
public Man()
{
}
[NotifyHandler] //Expected: this handler should be called when FirstName property set
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
}
public class NotifyHandler : ICallHandler
{
public Boolean Before { get; set; }
public Boolean After { get; set; }
public String Message { get; set; }
int ICallHandler.Order { get; set; }
IMethodReturn ICallHandler.Invoke(IMethodInvocation input,
GetNextHandlerDelegate getNext)
{
if (this.Before == true)
{
Debug.WriteLine(this.Message);
}
IMethodReturn result = getNext()(input, getNext);
if (result.Exception != null)
{
Debug.WriteLine(result.Exception.Message);
}
else
{
if (this.After == true)
{
Debug.WriteLine(this.Message);
}
}
return (result);
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property
| AttributeTargets.Method)]
Public class NotifyHandlerAttribute : HandlerAttribute
{
public NotifyHandlerAttribute()
{
}
public override ICallHandler CreateHandler(IUnityContainer ignored)
{
return new NotifyHandler();
}
}
public abstract class HandlerAttribute : Attribute
{
/// Derived classes implement this method. When called, it creates a
/// new call handler as specified in the attribute configuration.
/// The parameter "container" specifies the IUnityContainer
/// to use when creating handlers, if necessary.
/// returns a new call handler object.
public abstract ICallHandler CreateHandler(IUnityContainer container);
private int executionorder;
/// <summary>
/// Gets or sets the order in which the handler will be executed.
/// </summary>
public int Order
{
get { return this.executionorder; }
set { this.executionorder = value; }
}
}
//Interception registered in the application start up
private void Application_Startup(object sender, StartupEventArgs e)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<Man>().Configure<Interception>();
var m1 =container.Resolve<Man>();
m1.FirstName = "test";
Man m = new Man();
m.FirstName = "fine";
}
在上面这两个 FirstName setter 属性都没有调用 NotifyHandler。