问题描述:

I wish to implement suspend and resume binding in silverlight using a flag while doing heavy operation in a binding scenario.

My problem is in the existing project uses heavy binding drawing mechanismm.

Using UpdateTrigger() in silverlight we could achieve manual triggering of binding.

But its a huge product. Its not possible to update and find the locations for manual triggering of binding and so on and change the project.

So we planned to use Microsoft Unity to quickly fix by suspend and resume binding using a flag on heavy load drawing operation. This may be quick fix for the current performance issue while drawing binding objects.

I wish to check a bool flag before setting value to the properties for different Type?

I googled so much and tired to find Interception before property setter. But not found a way. Still fighting. This is my exact requirement.

Anybody to help?

Added the sample code trying,

//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";

}

In above both the FirstName setter property does not call the NotifyHandler.

相关阅读:
Top