Example #1
0
        public void WriteToSeveralPropertiesAndFields()
        {
            var t        = new ClassWithWritablePropertiesAndFields <int>();
            var elements = t.GetType().GetPublicPropertiesAndFields().ToArray();

            var actual = elements.Accept(new ValueWritingVisitor(t));

            actual.Value(42);

            Assert.Equal(42, t.Field1);
            Assert.Equal(42, t.Field2);
            Assert.Equal(42, t.Property1);
            Assert.Equal(42, t.Property2);
        }
Example #2
0
        public void WriteToSeveralPropertiesAndFields()
        {
            var t = new ClassWithWritablePropertiesAndFields<int>();
            var elements = t.GetType()
                .GetProperties()
                .Select(pi => new PropertyInfoElement(pi))
                .Cast<IReflectionElement>()
                .Concat(t.GetType()
                    .GetFields()
                    .Select(fi => new FieldInfoElement(fi))
                    .Cast<IReflectionElement>())
                .ToArray();
            var visitor = new ValueWritingVisitor(t);

            var actual =
                new CompositeReflectionElement(elements).Accept(visitor);
            actual.Value(42);

            Assert.Equal(42, t.Field1);
            Assert.Equal(42, t.Field2);
            Assert.Equal(42, t.Property1);
            Assert.Equal(42, t.Property2);
        }
Example #3
0
        public void WriteToSeveralPropertiesAndFields()
        {
            var t = new ClassWithWritablePropertiesAndFields<int>();
            var elements = t.GetType().GetPublicPropertiesAndFields().ToArray();

            var actual = elements.Accept(new ValueWritingVisitor(t));
            actual.Value(42);
            
            Assert.Equal(42, t.Field1);
            Assert.Equal(42, t.Field2);
            Assert.Equal(42, t.Property1);
            Assert.Equal(42, t.Property2);
        }