Пример #1
0
        protected bool CompileExpression(string expr)
        {
            try
            {
                CompiledExpression <TValue> ce = new CompiledExpression <TValue>(expr);
                var del = ce.ScopeCompile <TScope>();
                //var ex = ce.Expression as Expression<Func<TScope, TValue>>;
                var ex     = ce.Expression;
                var set    = ExpressionUtilities.FindMembers(ex, scope);
                var val    = del(scope);
                var oldVal = cachedValue;

                // If we get to this point, everything worked so we can assign the vars
                valueDelegate   = del;
                valueExpression = ce;
                cachedValue     = val;
                pending         = false;
                SetWatchedSubscriptions(set);
                if (!oldVal.Equals(cachedValue))
                {
                    RaisePropertyChanged(nameof(Value));
                }
                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
Пример #2
0
        public void TestIntTagDiscovery()
        {
            string exText = "TagI1 + TagI2.FinalValue";

            var scope = new TestScope();

            var ce  = new CompiledExpression <double>(exText);
            var del = ce.ScopeCompile <TestScope>();
            var r   = del(scope);

            var result = ExpressionUtilities.FindMembers(ce.Expression, scope);

            var key1    = scope.TagI1 as INotifyPropertyChanged;
            var key2    = scope.TagI2 as INotifyPropertyChanged;
            var result1 = result[key1];
            var result2 = result[key2];

            Assert.True(result.ContainsKey(key1), "tag1 not found");
            Assert.True(result.ContainsKey(key2), "tag2 not found");
            Assert.True(result[key1].Contains("Value"));
            Assert.True(result[key2].Contains("FinalValue"));
        }