public void CreateStaticSetter1Works()
        {
            var field = typeof(Corge).GetField(nameof(Corge.Bar));

            Action <int> setter;
            var          queued = (Callback : (WaitCallback)null !, FieldSetter : (StaticFieldSetter <int>)null !);

            void queueUserWorkItem(WaitCallback callback, object state) => queued = (callback, (StaticFieldSetter <int>)state);

            FieldInfoExtensions.SetQueueUserWorkItemAction(queueUserWorkItem);

            try
            {
                setter = field !.CreateStaticSetter <int>();
            }
            finally
            {
                FieldInfoExtensions.SetQueueUserWorkItemAction(null !);
            }

            // Verify that a work item was queued
            queued.FieldSetter.Should().NotBeNull();
            queued.Callback.Should().NotBeNull();

            // Verify that the return delegate is correct
            setter.Target.Should().BeSameAs(queued.FieldSetter);
            setter.Method.Name.Should().Be(nameof(StaticFieldSetter <int> .SetValue));
            setter.Method.DeclaringType.Should().Be(typeof(StaticFieldSetter <int>));

            // Verify that the queued Callback calls the SetOptimizedFunc
            // method of the queued FieldSetter.
            var beforeAction = queued.FieldSetter.Action;

            queued.Callback.Invoke(queued.FieldSetter);
            var afterAction = queued.FieldSetter.Action;

            beforeAction.Should().NotBeSameAs(afterAction);
        }
        public void CreateGetter2Works()
        {
            Func <Foo, int> getter;
            var             queued = (Callback : (WaitCallback)null !, FieldGetter : (FieldGetter <Foo, int>)null !);

            void queueUserWorkItem(WaitCallback callback, object state) => queued = (callback, (FieldGetter <Foo, int>)state);

            FieldInfoExtensions.SetQueueUserWorkItemAction(queueUserWorkItem);

            try
            {
                getter = _field.CreateGetter <Foo, int>();
            }
            finally
            {
                FieldInfoExtensions.SetQueueUserWorkItemAction(null !);
            }

            // Verify that a work item was queued
            queued.FieldGetter.Should().NotBeNull();
            queued.Callback.Should().NotBeNull();

            // Verify that the return delegate is correct
            getter.Target.Should().BeSameAs(queued.FieldGetter);
            getter.Method.Name.Should().Be(nameof(FieldGetter <Foo, int> .GetValue));
            getter.Method.DeclaringType.Should().Be(typeof(FieldGetter <Foo, int>));

            // Verify that the queued Callback calls the SetOptimizedFunc
            // method of the queued FieldGetter.
            var beforeFunc = queued.FieldGetter.Func;

            queued.Callback.Invoke(queued.FieldGetter);
            var afterFunc = queued.FieldGetter.Func;

            beforeFunc.Should().NotBeSameAs(afterFunc);
        }