コード例 #1
0
ファイル: Interfacenterceptor.cs プロジェクト: lwhans/config
        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);
            }
        }
コード例 #2
0
 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]);
     }
 }
コード例 #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]);
                    }
                }
            }
コード例 #4
0
ファイル: DynamicReader.cs プロジェクト: jpommers/config
        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));
        }
コード例 #5
0
        private void WriteProperty(PropertyResultBox pbox, object[] arguments)
        {
            string path = OptionPath.Combine(_basePath, pbox.StoreByName);

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