private void Dispatch(Node node)
        {
            if (node == null)
            {
                TraverseNull(null);
            }
            else
            {
                if (!_dispatchCache.ContainsKey(node.GetType()))
                {
                    var types = _visitors.Keys;
                    var thunk1 = new IsSuitable_Thunk(node);
                    var suitable = types.Where(thunk1.Snippet).ToReadOnly();
                    var thunk2 = new IsBetter_Thunk(suitable);
                    var better = suitable.Where(thunk2.Snippet).ToReadOnly();
                    _dispatchCache.Add(node.GetType(), better.SingleOrDefault());
                }

                var target = _dispatchCache[node.GetType()];
                if (target != null)
                {
                    _visitors[target](node);
                }
                else
                {
                    node.Unsupported();
                }
            }
        }
示例#2
0
        private T Dispatch(Node node)
        {
            if (node == null)
            {
                return(ReduceNull(null));
            }
            else
            {
                if (!_dispatchCache.ContainsKey(node.GetType()))
                {
                    var types    = _visitors.Keys;
                    var thunk1   = new IsSuitable_Thunk(node);
                    var suitable = types.Where(thunk1.Snippet).ToReadOnly();
                    var thunk2   = new IsBetter_Thunk(suitable);
                    var better   = suitable.Where(thunk2.Snippet).ToReadOnly();
                    _dispatchCache.Add(node.GetType(), better.SingleOrDefault());
                }

                var target = _dispatchCache[node.GetType()];
                if (target != null)
                {
                    return(_visitors[target](node));
                }
                else
                {
                    throw node.Unsupported();
                }
            }
        }
示例#3
0
        private Node Dispatch(Node node)
        {
            if (node == null)
            {
                return(null);
            }
            else
            {
                if (!_dispatchCache.ContainsKey(node.GetType()))
                {
                    var types    = _visitors.Keys;
                    var thunk1   = new IsSuitable_Thunk(node);
                    var suitable = types.Where(thunk1.Snippet).ToReadOnly();
                    var thunk2   = new IsBetter_Thunk(suitable);
                    var better   = suitable.Where(thunk2.Snippet).ToReadOnly();
                    _dispatchCache.Add(node.GetType(), better.SingleOrDefault());
                }

                var target = _dispatchCache[node.GetType()];
                return(target != null ? _visitors[target](node) : node.DefaultTransform());
            }
        }
        private Node Dispatch(Node node)
        {
            if (node == null)
            {
                return null;
            }
            else
            {
                if (!_dispatchCache.ContainsKey(node.GetType()))
                {
                    var types = _visitors.Keys;
                    var thunk1 = new IsSuitable_Thunk(node);
                    var suitable = types.Where(thunk1.Snippet).ToReadOnly();
                    var thunk2 = new IsBetter_Thunk(suitable);
                    var better = suitable.Where(thunk2.Snippet).ToReadOnly();
                    _dispatchCache.Add(node.GetType(), better.SingleOrDefault());
                }

                var target = _dispatchCache[node.GetType()];
                return target != null ? _visitors[target](node) : node.DefaultTransform();
            }
        }