/// <summary> /// Gets an instruction representing a load-by-value from the given local. /// </summary> /// <param name="local">Local to load</param> /// <returns>Loading instruction</returns> public static MsilInstruction AsValueLoad(this MsilLocal local) { switch (local.Index) { case 0: return(new MsilInstruction(OpCodes.Ldloc_0)); case 1: return(new MsilInstruction(OpCodes.Ldloc_1)); case 2: return(new MsilInstruction(OpCodes.Ldloc_2)); case 3: return(new MsilInstruction(OpCodes.Ldloc_3)); default: return(new MsilInstruction(local.Index < 0xFF ? OpCodes.Ldloc_S : OpCodes.Ldloc).InlineValue(local)); } }
/// <summary> /// Gets an instruction representing a load-by-reference from the given local. /// </summary> /// <param name="local">Local to load</param> /// <returns>Loading instruction</returns> public static MsilInstruction AsReferenceLoad(this MsilLocal local) { return(new MsilInstruction(local.Index < 0xFF ? OpCodes.Ldloca_S : OpCodes.Ldloca).InlineValue(local)); }