Example #1
0
        public void TestGenerateIGetterForStudentNumber()
        {
            // Arrange
            IGetter getter = dynamicIGetterInstanceCreator.CreateIGetterForField(typeof(Student), "nr");

            // // Asserts
            Assert.NotNull(getter);
            Assert.AreEqual("nr", getter.GetName());
            Assert.AreEqual(s1.nr, (int)getter.GetValue(s1));
        }
        public void TestGenerateIGetterForStudentName()
        {
            // Arrange
            IGetter getter = dynamicIGetterInstanceCreator.CreateIGetterFor(typeof(Student), typeof(Student).GetField("name"));

            // // Asserts
            Assert.NotNull(getter);
            Assert.Equal("name", getter.GetName());
            Assert.Equal(s1.name, (string)getter.GetValue(s1));
        }
        public void TestDynamicGetterForStudentNr()
        {
            //
            // Arrange
            //
            DynamicGetterBuider builder = new DynamicGetterBuider(typeof(Student));
            Type    getterType          = builder.GenerateGetterFor(typeof(Student).GetField("nr"));
            IGetter getter = (IGetter)Activator.CreateInstance(getterType);
            // builder.SaveModule();
            //
            // Act
            //
            Student st = new Student(762354, "Ze Manel", 13, "zemanel");

            Assert.Equal("nr", getter.GetName());
            Assert.Equal(762354, getter.GetValue(st));
        }
Example #4
0
 public object GetValue(object target)
 {
     return(formatter.Format(getter.GetValue(target)));
 }
Example #5
0
        public void Replace(object obj, IGetter getter, Slicer slicer)
        {
            var value = getter.GetValue(obj);

            slicer[index, length] = _formatter.Map(f => f.Format(value)).DefaultTo(() => value.ToNonNullString());
        }