Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Understanding Reflection
1.
2. Understanding Reflection Tamir Khason Technology Consultor ¹ mPrest Systems http://blogs.microsoft.co.il/blogs/tamir Session Code: DVP307 ¹ con·sul·tor (kən sult ′ ər) - one of a group of priests appointed to advise and assist a bishop
3. CLR – compilation and execution Execution Compilation Source code Language compiler JIT compiler Before installation or the first time each method is called MSIL Metadata Code Native code
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14. We can clone it… Type kidType = oldKid.GetType(); Kid newKid = new Kid(); foreach (var m in kidType.GetProperties()) { m.SetValue(newKid , m.GetValue(oldKid, null), null); } Unknown object GetType().GetMembers() For Each Member FieldInfo.Copy old value to new Object
15. Clone optimization Kid CloneKid(Kid) { newKid.Height = oldKid.Height newKid.Weight = oldKid.Weight } Unknown object GetType().GetMembers() For Each Member Create Code that copies members Save as Method for later Invocation