Merge pull request #457 from strawd/aspnetwebstack-resources
[mono.git] / mcs / class / System.Core / System.Linq.Expressions / ParameterExpression.cs
index e4cd848bbaedf3063ad21cacb2f9da594f7b9e17..651f9a90b94c71532848e5db6b2e75cd070b5b62 100644 (file)
@@ -46,9 +46,41 @@ namespace System.Linq.Expressions {
                        this.name = name;
                }
 
+               void EmitLocalParameter (EmitContext ec, int position)
+               {
+                       ec.ig.Emit (OpCodes.Ldarg, position);
+               }
+
+               void EmitHoistedLocal (EmitContext ec, int level, int position)
+               {
+                       ec.EmitScope ();
+
+                       for (int i = 0; i < level; i++)
+                               ec.EmitParentScope ();
+
+                       ec.EmitLoadLocals ();
+
+                       ec.ig.Emit (OpCodes.Ldc_I4, position);
+                       ec.ig.Emit (OpCodes.Ldelem, typeof (object));
+
+                       ec.EmitLoadStrongBoxValue (Type);
+               }
+
                internal override void Emit (EmitContext ec)
                {
-                       ec.ig.Emit (OpCodes.Ldarg, ec.GetParameterPosition (this));
+                       int position = -1;
+                       if (ec.IsLocalParameter (this, ref position)) {
+                               EmitLocalParameter (ec, position);
+                               return;
+                       }
+
+                       int level = 0;
+                       if (ec.IsHoistedLocal (this, ref level, ref position)) {
+                               EmitHoistedLocal (ec, level, position);
+                               return;
+                       }
+
+                       throw new InvalidOperationException ("Parameter out of scope");
                }
        }
 }