Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- namespace zadanie_113
- {
- class Przyklad
- {
- public int publika { get; set; }
- private int prywata { get; set; }
- public Przyklad()
- {
- publika = 5;
- prywata = 5;
- }
- private int ten()
- {
- return 10;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Przyklad p = new Przyklad();
- Type typ = typeof(Przyklad);
- PropertyInfo priv = typ.GetProperty("prywata", BindingFlags.NonPublic | BindingFlags.Instance);
- Console.WriteLine("Wartość przed: {0}", priv.GetValue(p));
- priv.SetValue(p, 4);
- Console.WriteLine("Wartość po: {0}", priv.GetValue(p));
- MethodInfo met = typ.GetMethod("ten", BindingFlags.NonPublic | BindingFlags.Instance);
- Console.WriteLine(met.Invoke(p, null));
- PropertyInfo pub = typ.GetProperty("publika");
- for(int i = 0; i < 4; i++)
- pub.GetValue(p);
- DateTime Start = DateTime.Now;
- for(int i = 0; i < 1000000; i++)
- pub.GetValue(p);
- DateTime End = DateTime.Now;
- TimeSpan Time = End - Start;
- Console.WriteLine("Czas dla refleksji: {0}", Time);
- int trial = p.publika;
- for(int i = 0; i < 4; i++)
- trial = p.publika;
- Start = DateTime.Now;
- for(int i = 0; i < 1000000; i++)
- trial = p.publika;
- End = DateTime.Now;
- Time = End - Start;
- Console.WriteLine("Czas dla normalnego sposobu: {0}", Time);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement