Event Filters - Custom

You can create your own event filters by implementing the IEventFilter interface and then using the SetEventFilterAttribute to attach your event filter to a MetaProperty.

The IEventFilter interface looks like this:

    public interface IEventFilter
        void SetMetaPropertyConfiguration(MetaPropertyConfiguration configuration);

        void PerformFilter(object sender, EventArgs args, IFilterPipeline pipeline);

The SetMetaPropertyConfiguration method is called when the MetaProperty is initialized and contains the full configuration for the MetaProperty. This may or may not be useful to your event filter.

The PerformFilter method is where your filter does its work. Anything can happen in this method, but once your work is done you should call the IFilterPipeline.Resume method to resume processing the remainder of the filter pipeline. Failing to call this method means any events will be suppressed.

The following example simply traces a message and resumes the pipeline:

    public void PerformFilter(object sender, EventArgs args, IFilterPipeline pipeline)
        System.Diagnostics.Trace.WriteLine("Hello world");
        pipeline.Resume(sender, args);

Event filter exceptions

Any exceptions thrown from your event filter will be handled by the IsolatingEventFilter which is automatically inserted into the pipeline for you by the MetaProperties framework.

If nothing is attached to the IsolatingEventFilter.UnhandledEventHandlerException event then the exception will be rethrown as if the IsolatingEventFilter didn't exist.

If your event filter is dispatching to other threads then any exceptions thrown in those threads should be handled yourself if required.

Last edited Mar 9, 2010 at 2:19 PM by jamesthurley, version 2


No comments yet.