Cancelling Default Execution

Topics: Policy Injection Application Block
Jul 7, 2010 at 10:29 AM


I want to write a custom ICallHandler that cancels default execution when setter properties are called. The problem is, I don't know what to return/do in this case.

Here is my code:

public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
	String propertyName = input.MethodBase.Name.Substring(4);
	Boolean isSetter = input.MethodBase.Name.StartsWith("set_") == true;
	IMethodReturn result = null;

	if (isSetter != true)
		result = getNext()(input, getNext);
	return (result);

Any ideas?


Ricardo Peres


Jul 7, 2010 at 10:58 AM

If you want to cancel the processing of the rest of the handlers, you can make use of return input.CreateExceptionMethodReturn(exceptionObject);  If you simply want to cancel the execution without an exception, you can use return input.CreateMethodReturn(null, null).  This will allow the previous handlers' pre-processing tasks to still execute.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 7, 2010 at 11:09 AM

Hello, Sarah, thanks for the quick answer!

It worked, I just had to change those nasty nulls, because they cause an exception:

result = input.CreateMethodReturn(new Object(), new Object[0]);

Best regards,

Ricardo Peres

Jul 7, 2010 at 11:14 AM

Ooops, sorry bout that.  Anyway, glad to be of help.