private void CreateByRefAliasing(bool useInterpreter) { ParameterExpression pX = Expression.Parameter(typeof(int).MakeByRefType()); ParameterExpression pY = Expression.Parameter(typeof(int).MakeByRefType()); ByRefNewFactory2 del = Expression.Lambda <ByRefNewFactory2>( Expression.New(typeof(ByRefNewType).GetConstructors()[0], pX, pY), pX, pY).Compile(useInterpreter); int x = 3; Assert.NotNull(del(ref x, ref x)); Assert.Equal(16, x); }
public void CreateByRefThrowing(bool useInterpreter) { ParameterExpression pX = Expression.Parameter(typeof(int).MakeByRefType()); ParameterExpression pY = Expression.Parameter(typeof(int).MakeByRefType()); ByRefNewFactory2 del = Expression.Lambda <ByRefNewFactory2>( Expression.New(typeof(ByRefNewType).GetConstructors()[0], pX, pY), pX, pY).Compile(useInterpreter); int x = -9; int y = 4; AssertExtensions.Throws <ArgumentOutOfRangeException>("x", () => del(ref x, ref y)); }