public void VarConstruction()
        {

            object s = "";
            ValuePointer var = new ValuePointer(() => s, (o) => s = o, null, false);
            var.Setter(1);
            Assert.AreEqual(1, s);
            Assert.IsNull(var.DeclaredType);
            Assert.IsFalse(var.IsDynamic);

            var.UpdateToCurrentType();
            Assert.IsNotNull(var.DeclaredType);
            try { var.Setter("Var.Setter"); Assert.Fail(); } catch { }
        }
        public void DefinedDynamicConstruction()
        {

            object s = "";
            ValuePointer definedDynamic = new ValuePointer(() => s, (o) => s = o, typeof(string), true);
            Assert.IsTrue(definedDynamic.IsDynamic);

            definedDynamic.Setter(3);
            Assert.AreEqual(3, s);
            Assert.IsTrue(definedDynamic.IsDynamic);

            definedDynamic.Setter("definedDynamic.Setter");
            Assert.AreEqual("definedDynamic.Setter", s);
            Assert.IsTrue(definedDynamic.IsDynamic);
        }
        public void DynamicConstruction()
        {
            object s = "";
            ValuePointer dynamic = new ValuePointer(() => s, (o) => s = o, null, true);
            Assert.IsTrue(dynamic.IsDynamic);
            Assert.IsNull(dynamic.DeclaredType);

            dynamic.Setter("dynamic.Setter");
            Assert.IsTrue(dynamic.IsDynamic);
            Assert.IsNull(dynamic.DeclaredType);

            dynamic.UpdateToCurrentType();
            Assert.IsTrue(dynamic.IsDynamic);

            try { dynamic.Setter(123); } catch { Assert.Fail(); }
        }
        public void IncompatibleStaticConstruction()
        {
            object s = "";
            ValuePointer incompatibleStatic = new ValuePointer(() => s, (o) => s = o, typeof(int), false);

            Assert.AreEqual(typeof(int), incompatibleStatic.DeclaredType);
            Assert.IsFalse(incompatibleStatic.IsDynamic);
            incompatibleStatic.Setter(1);
            Assert.AreEqual(1, s);
            Assert.AreEqual(typeof(int), incompatibleStatic.DeclaredType);
            try
            {
                incompatibleStatic.Setter("Fail");
                Assert.Fail();
            }
            catch { }
        }
        public void IncompatibleDynamicConstruction()
        {

            object s = "";
            ValuePointer incompatibleDynamic = new ValuePointer(() => s, (o) => s = o, typeof(int), true);
            Assert.IsTrue(incompatibleDynamic.IsDynamic);
            Assert.AreEqual(typeof(int), incompatibleDynamic.DeclaredType);

            incompatibleDynamic.Setter("dynamic.Setter");
            Assert.IsTrue(incompatibleDynamic.IsDynamic);

            incompatibleDynamic.UpdateToCurrentType();
            Assert.AreEqual(typeof(string), incompatibleDynamic.DeclaredType);
            Assert.IsTrue(incompatibleDynamic.IsDynamic);


            try
            {
                incompatibleDynamic.Setter(123);
                Assert.Fail();
            }
            catch { }
        }
        public void ActionPointerConstruction()
        {

            object s = 123;
            object func = null;

            ValuePointer funcPointer = new ValuePointer(() => func, (o) => func = o, typeof(Action<object>), false);

            funcPointer.Setter(new Action<object>((val) => s = val));

            ((Action<object>)funcPointer.Getter())(12);

            Assert.AreEqual(12, s); //Check that the action correctly set 12
        }
        public void FuncPointerConstruction()
        {

            object s = 123;
            object func = null;

            ValuePointer funcPointer = new ValuePointer(() => func, (o) => func = o, typeof(Func<object>), false);

            funcPointer.Setter(new Func<object> (() => s));

            object obj = ((Func<object>)funcPointer.Getter())();

            Assert.AreEqual(s, obj); //Check that we got the correct object
        }