コード例 #1
0
        private string[] GetCapturedLoopVariablesNames()
        {
            var capturedVariables = LambdaBlock.GetCapturedLoopVariables(this.Emitter, this.Context, this.Parameters);

            if (capturedVariables == null)
            {
                return(null);
            }

            List <string> names = new List <string>();

            foreach (var capturedVariable in capturedVariables)
            {
                if (this.Emitter.LocalsMap != null && this.Emitter.LocalsMap.ContainsKey(capturedVariable))
                {
                    names.Add(this.RemoveReferencePart(this.Emitter.LocalsMap[capturedVariable]));
                }
                else if (this.Emitter.LocalsNamesMap != null && this.Emitter.LocalsNamesMap.ContainsKey(capturedVariable.Name))
                {
                    names.Add(this.RemoveReferencePart(this.Emitter.LocalsNamesMap[capturedVariable.Name]));
                }
                else
                {
                    names.Add(capturedVariable.Name);
                }
            }

            return(names.ToArray());
        }
コード例 #2
0
        public override void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression)
        {
            var capturedVariables = LambdaBlock.GetCapturedLoopVariables(this.Emitter, anonymousMethodExpression, anonymousMethodExpression.Parameters, true);

            if (capturedVariables != null)
            {
                DirectionVariables.AddRange(capturedVariables);
            }

            base.VisitAnonymousMethodExpression(anonymousMethodExpression);
        }
コード例 #3
0
        public override void VisitLambdaExpression(LambdaExpression lambdaExpression)
        {
            var capturedVariables = LambdaBlock.GetCapturedLoopVariables(this.Emitter, lambdaExpression, lambdaExpression.Parameters, true);

            if (capturedVariables != null)
            {
                DirectionVariables.AddRange(capturedVariables);
            }

            base.VisitLambdaExpression(lambdaExpression);
        }
コード例 #4
0
        internal static IVariable[] GetCapturedLoopVariables(IEmitter emitter, AstNode context, IEnumerable <ParameterDeclaration> parameters, bool excludeReadOnly = false)
        {
            var loop = LambdaBlock.GetOuterLoop(context);

            if (loop == null)
            {
                return(null);
            }

            var loopVariablesAnalyzer = new LoopVariablesAnalyzer(emitter, excludeReadOnly);

            loopVariablesAnalyzer.Analyze(loop);

            var captureAnalyzer = new CaptureAnalyzer(emitter);

            captureAnalyzer.Analyze(context, parameters.Select(p => p.Name));
            return(captureAnalyzer.UsedVariables.Where(v => loopVariablesAnalyzer.Variables.Contains(v)).ToArray());
        }