public override void GenerateCode(Emit.ILGenerator ilg, ExecutionContext ec) { /* * Check for two things: * 1) Is it an argument? * 2) Is it a local variable (or global) */ var arg = ec.GetParameter(varName); if (arg != null) { //This is an argument - we need to store it in its index. ilg.Emit(Emit.OpCodes.Starg, arg.Position); return; } var varDec = ec.GetVariable(varName); if (varDec == null) { //The person wants this to be a local variable. It has not been declared, so we must do it for them. varDec = ilg.DeclareLocal(e.GetEvaluatedType(ec)); ec.AddVariable(varName, varDec); } e.Push(ilg, ec); ilg.Emit(Emit.OpCodes.Stloc, varDec); //Store the result of the expression. }