C # create a message Interceptor (intercept) 3

Source: Internet
Author: User

Previously, the "intercept" attribute (interceptproperty) was added to the context of interceptattribute. Because interceptproperty inherits icontributeobjectsink, we need to implement getobjectsink (), then we need to create a class that inherits imessagesink as the return value.

In this way, the implementation of the interceptsink class is introduced:

public class InterceptSink : IMessageSink    {        private IMessageSink nextSink = null;        public IMessageSink NextSink        {            get { return nextSink; }        }        public InterceptSink(IMessageSink nextSink)        {            Console.WriteLine(" Call 'InterceptSink' - 'Constructor'  ");            this.nextSink = nextSink;        }                public IMessage SyncProcessMessage(IMessage msg)        {                        Console.WriteLine("method_name: " + msg.Properties["__MethodName"].ToString());            IMessage returnMsg = nextSink.SyncProcessMessage(msg);            return returnMsg;        }        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)        {            return null;        }    }

Core Method: syncprocessmessage (iMessage MSG)

In the input parameter MSG, we can find the corresponding data for calling the object method.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.