Beispiel #1
0
        public void Intercept(IInvocation invocation)
        {
            if (TryInterceptInpc(invocation))
            {
                return;
            }

            ResultBox rbox = FindBox(invocation);

            bool isRead =
                (rbox is PropertyResultBox && PropertyResultBox.IsGetProperty(invocation.Method)) ||
                (rbox is ProxyResultBox && 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);

                TryNotifyInpc(invocation, rbox);
            }
        }
 private ResultBox FindBox(IInvocation invocation)
 {
     if (PropertyResultBox.IsProperty(invocation.Method, out string propertyName))
     {
         return(_boxes[propertyName]);
     }
     else //method
     {
         string name = MethodResultBox.GetName(invocation.Method);
         return(_boxes[name]);
     }
 }
Beispiel #3
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]);
                    }
                }
            }
Beispiel #4
0
        private object ReadProperty(PropertyResultBox pbox, int index)
        {
            string path = OptionPath.Combine(index, _basePath, pbox.StoreByName);

            return(_ioHandler.Read(pbox.ResultBaseType, path, pbox.DefaultResult, pbox.ShouldEncrypt));
        }
Beispiel #5
0
        private void WriteProperty(PropertyResultBox pbox, object[] arguments)
        {
            string path = OptionPath.Combine(_basePath, pbox.StoreByName);

            _ioHandler.Write(pbox.ResultBaseType, path, arguments[0]);
        }