Example #1
0
        public static TriggerPath Factory(Expression path)
        {
            var body = (path as LambdaExpression)?.Body;

            var         e           = body;
            TriggerPath triggerPath = null;

            while (e != null)
            {
                var name = "";
                if (e.NodeType == ExpressionType.Convert)
                {
                    e = (e as UnaryExpression)?.Operand;
                }
                else
                {
                    switch (e)
                    {
                    case MemberExpression m:
                        name = m.Member.Name;
                        e    = m.Expression;
                        break;

                    case MethodCallExpression mc:
                        name = mc.Method.Name;
                        e    = mc.Arguments[0];
                        break;

                    default:
                        throw new ArgumentException("Error parsing expression : " + path.ToString());
                    }
                }

                if (e is { NodeType : ExpressionType.Parameter })
Example #2
0
        public static TriggerPath Factory(Expression path)
        {
            var body = (path as LambdaExpression)?.Body;

            if (body?.NodeType == ExpressionType.Convert)
            {
                body = (body as UnaryExpression)?.Operand;
            }

            var         e           = body;
            TriggerPath triggerPath = null;

            while (e != null)
            {
                var name = "";
                if (e is MemberExpression m)
                {
                    name = m.Member.Name;
                    e    = m.Expression;
                }
                else if (e is MethodCallExpression mc)
                {
                    name = mc.Method.Name;
                    e    = mc.Arguments[0];
                }
                else
                {
                    throw new ArgumentException("Error parsing expression : " + path.ToString());
                }

                if (e.NodeType == ExpressionType.Parameter)
                {
                    e           = null;
                    triggerPath = Factory(triggerPath, name);
                }
                else
                {
                    triggerPath = Factory(triggerPath, name);
                }
            }

            return(triggerPath);
        }
Example #3
0
        public static TriggerPath Factory(params string[] path)
        {
            var stack = new Stack <string>();

            foreach (var subPath in path)
            {
                var sub = subPath.Split('.');
                foreach (var propertyName in sub)
                {
                    stack.Push(propertyName);
                }
            }

            TriggerPath triggerPath = null;

            while (stack.TryPop(out var propertyName))
            {
                triggerPath = Factory(triggerPath, propertyName);
            }

            return(triggerPath ?? new TriggerPathNull());
        }
Example #4
0
 protected TriggerOnEntry(TriggerPath path, PropertyChangedEventHandler handler)
 {
     Path    = path;
     Handler = handler;
 }
Example #5
0
        public TriggerOnEntryNotifier(PropertyChangedEventHandler handler, INotifierPropertyEntry entry, TriggerPath path)
            : base(path, handler)
        {
            entry.PropertyChanged += Handler;
            _onDispose             = () => entry.PropertyChanged -= Handler;

            if (Path == null)
            {
                return;
            }

            void NextHandler(object sender, PropertyChangedEventArgs arg)
            {
                _next?.Dispose();
                if (arg is NotifierPropertyChangedEventArgs notifierArg)
                {
                    _next = notifierArg.NewValue != null?Subscribe(notifierArg.NewValue) : null;
                }
            }

            entry.RegisterValue += NextHandler;
            _onDispose          += () => entry.RegisterValue -= NextHandler;
            _onDispose          += () => _next?.Dispose();

            if (!entry.IsSet)
            {
                entry.Update();
            }

            var value = entry.GetValue();

            NextHandler(null, new NotifierPropertyChangedEventArgs(entry, null, value));
        }
Example #6
0
 private static TriggerPath Factory(TriggerPath next, string propertyName)
 {
     return(next == null ? new TriggerPath(propertyName) : new TriggerPathNext(next, propertyName));
 }
Example #7
0
 internal TriggerPathNext(TriggerPath next, string propertyName) : base(propertyName)
 {
     Next = next;
 }
Example #8
0
 public TriggerOnAttribute(params string[] path)
 {
     Path = TriggerPath.Factory(path);
 }
        public TriggerOnEntryCollection(PropertyChangedEventHandler handler, INotifyCollectionChanged collection, TriggerPath path)
            : base(path, handler)
        {
            _collection = collection;

            if (path != null)
            {
                _collection.CollectionChanged += OnCollectionChanged_Subscribe;
                OnCollectionChanged_Subscribe(collection, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)_collection));
            }
            _collection.CollectionChanged += OnCollectionChanged_Handler;
        }