Пример #1
0
 public void reset_the_counter_and_print_the_return_value_of_method2()
 {
     var field = type.GetField("Counter", BindingFlags.NonPublic | BindingFlags.Static);
     field.SetValue(null, 0);
     var obj = new ReflectionTarget();
     var method = type.GetMethod("Method2");
     var retVal = method.Invoke(obj, new []{"hello world"});
     Console.WriteLine(retVal);
 }
Пример #2
0
 public void invoke_method2_twice_printing_the_return_value_each_time()
 {
     var obj = new ReflectionTarget();
     var method = type.GetMethod("Method2");
     for (var i = 0; i < 2; i++)
     {
         var retVal = method.Invoke(obj, new[] {"hello world"});
         Console.WriteLine(retVal);
     }
 }
Пример #3
0
 public void set_the_value_of_each_property_then_print_the_to_string_value()
 {
     var obj = new ReflectionTarget();
     var props = type.GetProperties();
     var i = 10;
     foreach (var prop in props)
     {
         i++;
         prop.SetValue(obj, i.ToString());
         Console.WriteLine(prop.GetValue(obj).ToString());
     }
 }