public void Intercept(IInvocation invocation)
        {
            ResultBox rbox = FindBox(invocation);

            bool isRead =
                (rbox is PropertyResultBox pbox && PropertyResultBox.IsGetProperty(invocation.Method)) ||
                (rbox is ProxyResultBox xbox && PropertyResultBox.IsGetProperty(invocation.Method)) ||
                (rbox is MethodResultBox mbox && mbox.IsGettter) ||
                (rbox is CollectionResultBox);

            if (isRead)
            {
                invocation.ReturnValue = _reader.Read(rbox, -1, invocation.Arguments);
                return;
            }
            else
            {
                _writer.Write(rbox, invocation.Arguments);
            }
        }
Beispiel #2
0
        public void Write(ResultBox rbox, object[] arguments)
        {
            if (rbox is PropertyResultBox pbox)
            {
                WriteProperty(pbox, arguments);
            }

            else if (rbox is MethodResultBox mbox)
            {
                WriteMethod(mbox, arguments);
            }

            else if (rbox is ProxyResultBox xbox)
            {
                WriteProxy(xbox, arguments);
            }

            else
            {
                throw new NotImplementedException($"don't know how to write {rbox.GetType()}");
            }
        }
Beispiel #3
0
        public object Read(ResultBox rbox, int index = -1, params object[] arguments)
        {
            if (rbox is PropertyResultBox pbox)
            {
                return(ReadProperty(pbox, index));
            }

            if (rbox is ProxyResultBox xbox)
            {
                return(ReadProxy(xbox, index));
            }

            if (rbox is CollectionResultBox cbox)
            {
                return(ReadCollection(cbox, index));
            }

            if (rbox is MethodResultBox mbox)
            {
                return(ReadMethod(mbox, arguments));
            }

            throw new NotImplementedException($"don't know how to read {rbox.GetType()}");
        }
Beispiel #4
0
        public void Intercept(IInvocation invocation)
        {
            if (PropertyResultBox.IsProperty(invocation.Method, out bool isGetProperty, out string propertyName))
            {
                ResultBox rbox = _boxes[propertyName];

                if (rbox is ProxyResultBox proxy)
                {
                    if (!proxy.IsInitialised)
                    {
                        proxy.Initialise(_ioHandler, OptionPath.Combine(_prefix, proxy.StoreByName));
                    }

                    if (!isGetProperty)
                    {
                        throw new NotSupportedException("cannot assign values to interface properties");
                    }

                    //return a proxy interface
                    invocation.ReturnValue = proxy.ProxyInstance;
                }
                else
                {
                    PropertyResultBox pbox = (PropertyResultBox)rbox;
                    string            path = OptionPath.Combine(_prefix, pbox.StoreByName);

                    if (isGetProperty)
                    {
                        invocation.ReturnValue = _ioHandler.Read(pbox.ResultBaseType, path, pbox.DefaultResult);
                    }
                    else
                    {
                        _ioHandler.Write(pbox.ResultBaseType, path, invocation.Arguments[0]);
                    }
                }
            }