public void SetStatic()
        {
            Action <object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetProperty(typeof(StaticTestClass), "StringProperty"));

            setter(null, "New property!");
            Assert.AreEqual("New property!", StaticTestClass.StringProperty);

            setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetField(typeof(StaticTestClass), "StringField"));

            setter(null, "New field!");
            Assert.AreEqual("New field!", StaticTestClass.StringField);
        }
        public void CreateSetField_ReadOnly()
        {
            FieldsTestClass c = new FieldsTestClass();

            Action <object, object> setter =
                ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(
                    TestReflectionUtils.GetField(typeof(FieldsTestClass), "IntReadOnlyField")
                    );

            setter(c, int.MinValue);
            Assert.AreEqual(int.MinValue, c.IntReadOnlyField);
        }
        public void SetOnStruct()
        {
            object structTest = new StructTest();

            Action <object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetProperty(typeof(StructTest), "StringProperty"));

            setter(structTest, "Hi1");
            Assert.AreEqual("Hi1", ((StructTest)structTest).StringProperty);

            setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetField(typeof(StructTest), "StringField"));

            setter(structTest, "Hi2");
            Assert.AreEqual("Hi2", ((StructTest)structTest).StringField);
        }
        public void CreateSetField()
        {
            FieldsTestClass c = new FieldsTestClass();

            Action <object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetField(typeof(FieldsTestClass), "StringField"));

            setter(c, "String!");
            Assert.AreEqual("String!", c.StringField);

            setter = ExpressionReflectionDelegateFactory.Instance.CreateSet <object>(TestReflectionUtils.GetField(typeof(FieldsTestClass), "BoolField"));

            setter(c, true);
            Assert.AreEqual(true, c.BoolField);
        }
        public void GetStatic()
        {
            StaticTestClass.StringField    = "Field!";
            StaticTestClass.StringProperty = "Property!";

            Func <object, object> getter = ExpressionReflectionDelegateFactory.Instance.CreateGet <object>(TestReflectionUtils.GetProperty(typeof(StaticTestClass), "StringProperty"));

            object v = getter(null);

            Assert.AreEqual(StaticTestClass.StringProperty, v);

            getter = ExpressionReflectionDelegateFactory.Instance.CreateGet <object>(TestReflectionUtils.GetField(typeof(StaticTestClass), "StringField"));

            v = getter(null);
            Assert.AreEqual(StaticTestClass.StringField, v);
        }
        public void CreateGetField()
        {
            FieldsTestClass c = new FieldsTestClass
            {
                BoolField   = true,
                StringField = "String!"
            };

            Func <object, object> getter = ExpressionReflectionDelegateFactory.Instance.CreateGet <object>(TestReflectionUtils.GetField(typeof(FieldsTestClass), "StringField"));

            object value = getter(c);

            Assert.AreEqual("String!", value);

            getter = ExpressionReflectionDelegateFactory.Instance.CreateGet <object>(TestReflectionUtils.GetField(typeof(FieldsTestClass), "BoolField"));

            value = getter(c);
            Assert.AreEqual(true, value);
        }