コード例 #1
0
        public override IEnumerable <IGetter> GetMembers(Type t)
        {
            // First check if exist in members dictionary
            List <IGetter> ms;

            if (!members.TryGetValue(t, out ms))
            {
                DynamicGetterBuider builder = new DynamicGetterBuider(t);
                ms = new List <IGetter>();
                foreach (MemberInfo m in t.GetMembers())
                {
                    IGetter getter = null;
                    if (ShoudlLog(m, out getter))
                    {
                        // 1. Create the class that extends AbstractGetter for that member m in domain type t.
                        Type getterType = builder.GenerateGetterFor(m);
                        // 2. Instantiate the class created on 1.
                        getter = (IGetter)Activator.CreateInstance(getterType);
                        ms.Add(getter);
                    }
                }
                members.Add(t, ms);
            }
            return(ms);
        }
コード例 #2
0
        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));
        }