Exemple #1
0
        public void ReflectionDemo()
        {
            Type productType = typeof(Product);
            Product p = new Product();
            FieldInfo fi = productType.GetField("name",BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            fi.SetValue(p, "set by reflection");

            p.ID = 2;
            p.ShowProduct();
        }
Exemple #2
0
        public void PropertyDemo()
        {
            dynamic dyn = new Product();

            //dyn.name = "n1"; error

            dyn.ID = 1;
            dyn.ID = dyn.ID + 1;

            dyn.ShowProduct();
        }