Mono.CSharp.Linq.RangeVariable.CreateReferenceExpression C# (CSharp) Method

CreateReferenceExpression() public method

public CreateReferenceExpression ( ResolveContext rc, Location loc ) : Expression
rc ResolveContext
loc Location
return Expression
		public Expression CreateReferenceExpression (ResolveContext rc, Location loc)
		{
			Expression expr = null;

			// 
			// We know the variable name is somewhere in the scope. This generates
			// an access expression from current block
			//
			var pb = rc.CurrentBlock.ParametersBlock;
			while (true) {
				if (pb is QueryBlock) {
					for (int i = pb.Parameters.Count - 1; i >= 0; --i) {
						var p = pb.Parameters[i];
						if (p.Name == Name)
							return pb.GetParameterReference (i, loc);

						var tp = p as QueryBlock.TransparentParameter;
						while (tp != null) {
							if (expr == null)
								expr = pb.GetParameterReference (i, loc);
							else
								expr = new TransparentMemberAccess (expr, tp.Name);

							if (tp.Identifier == Name)
								return new TransparentMemberAccess (expr, Name);

							if (tp.Parent.Name == Name)
								return new TransparentMemberAccess (expr, Name);

							tp = tp.Parent as QueryBlock.TransparentParameter;
						}
					}

					expr = null;
				}

				if (pb == block)
					return null;

				pb = pb.Parent.ParametersBlock;
			}
		}
	}