Esempio n. 1
0
        public void PublicSetValueTypeInvalidInstanceStrict()
        {
            var setter = (typeof(PublicClass).Reflection().GetDescriptor("publicField") as IValueMemberDescriptor).ToCompiledSetValue();

            var instance = new NonPublicClass();

            Assert.Throws <InvalidCastException>(() => setter(instance, 42));
        }
Esempio n. 2
0
        public void NonPublicSetPrivateValueType()
        {
            var setter = (typeof(NonPublicClass).Reflection().GetDescriptor("privateField") as IValueMemberDescriptor).ToCompiledSetValue();

            var instance = new NonPublicClass();

            setter(instance, 42);

            Assert.Equal(42, instance.GetPrivateField());
        }
Esempio n. 3
0
        public void NonPublicSetInvalidReferenceTypeLoose()
        {
            var setter = (typeof(NonPublicClass).Reflection().GetDescriptor("disposableField") as IValueMemberDescriptor).ToCompiledSetValue(false);

            var instance = new NonPublicClass();

            setter(instance, 42);

            Assert.Throws <EntryPointNotFoundException>(() => instance.disposableField.Dispose());
        }
Esempio n. 4
0
        public void NonPublicGetReferenceTypeLoose()
        {
            var getter = (typeof(NonPublicClass).Reflection().GetDescriptor("disposableField") as IValueMemberDescriptor).ToCompiledGetValue(false);

            var instance = new NonPublicClass();

            instance.disposableField = Actions.Null.ToDisposable();

            Assert.NotNull(getter(instance));
        }
Esempio n. 5
0
        public void NonPublicGetValueTypeLoose()
        {
            var getter = (typeof(NonPublicClass).Reflection().GetDescriptor("publicField") as IValueMemberDescriptor).ToCompiledGetValue(false);

            var instance = new NonPublicClass();

            instance.publicField = 42;

            Assert.Equal(42, getter(instance));
        }
Esempio n. 6
0
        public void NonPublicSetReferenceType()
        {
            var setter = (typeof(NonPublicClass).Reflection().GetDescriptor("disposableField") as IValueMemberDescriptor).ToCompiledSetValue();

            var instance = new NonPublicClass();

            DateTime?value = null;

            setter(instance, Actions.Create(() => value = DateTime.Now).ToDisposable());

            Assert.NotNull(instance.disposableField);

            instance.disposableField.Dispose();

            Assert.NotNull(value);
        }