Mono.CSharp.EmitContext.TemporaryReturn C# (CSharp) Method

TemporaryReturn() public method

ReturnValue creates on demand the LocalBuilder for the return value from the function. By default this is not used. This is only required when returns are found inside Try or Catch statements. This method is typically invoked from the Emit phase, so we allow the creation of a return label if it was not requested during the resolution phase. Could be cleaned up, but it would replicate a lot of logic in the Emit phase of the code that uses it.
public TemporaryReturn ( ) : LocalBuilder
return System.Reflection.Emit.LocalBuilder
		public LocalBuilder TemporaryReturn ()
		{
			if (return_value == null){
				return_value = DeclareLocal (return_type, false);
				if (!HasReturnLabel){
					ReturnLabel = DefineLabel ();
					HasReturnLabel = true;
				}
			}

			return return_value;
		}
	}

Usage Example

Example #1
0
		protected override void DoEmit (EmitContext ec)
		{
			if (Expr != null) {
				Expr.Emit (ec);

				if (unwind_protect)
					ec.Emit (OpCodes.Stloc, ec.TemporaryReturn ());
			}

			if (unwind_protect)
				ec.Emit (OpCodes.Leave, ec.ReturnLabel);
			else
				ec.Emit (OpCodes.Ret);
		}
All Usage Examples Of Mono.CSharp.EmitContext::TemporaryReturn