Example #1
0
        public override IMessage Invoke(IMessage msg)
        {
            var call = new ObjectCall(this, msg, ConnectionTypeValidation, SchemaNameValidation);

            if (msg is IConstructionCallMessage)
            {
                context.DoCallBack(call.Initialize);
            }
            else if (msg is IMethodCallMessage)
            {
                context.DoCallBack(call.Execute);

                var methodInfo = (msg as IMethodCallMessage).MethodBase;

                // если вызываемый метод - Finalize или Dispose, то отключаем прокси от объекта
                bool isDestructor =
                    (methodInfo.Name == "Finalize" && methodInfo.GetParameters().Length == 0) ||
                    (methodInfo.Name == "Dispose" && methodInfo.DeclaringType == typeof(IDisposable));

                if (isDestructor)
                {
                    DetachServer();
                }
            }
            else
            {
                throw new Exception();
            }

            return(call.ReturnMessage);
        }
        public override IMessage Invoke(IMessage msg)
        {
            var call = new ObjectCall(this, msg, ConnectionTypeValidation, SchemaNameValidation);

            if (msg is IConstructionCallMessage)
            {
                context.DoCallBack(call.Initialize);
            }
            else if (msg is IMethodCallMessage)
            {
                context.DoCallBack(call.Execute);

                var methodInfo = (msg as IMethodCallMessage).MethodBase;

                // если вызываемый метод - Finalize или Dispose, то отключаем прокси от объекта
                bool isDestructor =
                    (methodInfo.Name == "Finalize" && methodInfo.GetParameters().Length == 0) ||
                    (methodInfo.Name == "Dispose" && methodInfo.DeclaringType == typeof(IDisposable));

                if (isDestructor)
                {
                    DetachServer();
                }
            }
            else
            {
                throw new Exception();
            }

            return call.ReturnMessage;
        }