Ejemplo n.º 1
0
        protected virtual bool TryCapture <T>(IFragmentBuilder parent, Expression node, out T result, out CaptureFragmentContext context) where T : IFragmentBuilder
        {
            context = new CaptureFragmentContext(parent, this.Query.Clone());
            var capture = new CaptureFragmentTarget(context);

            this.Push(capture);
            try
            {
                this.Visit(node);
            }
            finally
            {
                this.Pop(false);
            }
            foreach (var expression in context.Expressions)
            {
                if (expression is T)
                {
                    result = (T)expression;
                    return(true);
                }
            }
            result = default(T);
            return(false);
        }
Ejemplo n.º 2
0
        protected virtual T Capture <T>(IFragmentBuilder parent, Expression node, out CaptureFragmentContext context) where T : IFragmentBuilder
        {
            var expression = default(T);

            if (!this.TryCapture <T>(parent, node, out expression, out context))
            {
                throw new InvalidOperationException(string.Format("Failed to capture fragment of type \"{0}\".", typeof(T).FullName));
            }
            return(expression);
        }
Ejemplo n.º 3
0
 public CaptureFragmentTarget(CaptureFragmentContext context)
     : base(context.Parent, context.Graph)
 {
     this.Context = context;
 }