public void CreateDynamicGetDelegate_PublicFieldWithInstance_CanGetValue() { var box = new StrongBox <object>(new object()); var field = box.GetType().GetField(nameof(box.Value)) !; var getDelegate = field.CreateDynamicGetDelegate(box); var result = getDelegate.Invoke(); Assert.AreSame(box.Value, result); }
public void CreateDynamicSetDelegate_PublicField_CanSetValue() { var box = new StrongBox <object>(); var field = box.GetType().GetField(nameof(box.Value)) !; var setDelegate = field.CreateDynamicSetDelegate(); var value = new object(); setDelegate.Invoke(box, value); Assert.AreSame(value, box.Value); }
public void CreateSetDelegate_PublicFieldWithInstance_CanSetValue() { var box = new StrongBox <object>(); var field = box.GetType().GetField(nameof(box.Value)) !; var setDelegate = field.CreateSetDelegate <Action <object> >(box); var value = new object(); setDelegate.Invoke(value); Assert.AreSame(value, box.Value); }
static void Assign5() { Title(); var box = new StrongBox<int> { Value = 3 }; var obj = Log(Expression.Constant(box), "Box"); var val = box.GetType().GetField("Value"); var fld = Expression.Field(obj, val); var res = Expression.Lambda<Func<int>>(CSharpExpression.PreIncrementAssignChecked(fld)).Compile()(); Console.WriteLine($"{res} == (++3) --> {box.Value}"); }