コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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}");
        }