Reflection is one of the new features of .NET and it's way cool. In a nutshell, Reflection allows you to interrogate an object, your's or someone elses, and find out all about it at runtime. Let me show you a really simple illustration. Let's say that I have an object called Broadcaster (I made a Broadcaster object for another article, so I was just being object-oriented (or lazy depending who you ask) ) and you want to see all of its members...this just a few lines of code will get you there:
In VB.NET Type:
| Dim t As Type = c.GetType Dim ObjectMembers As MemberInfo() = t.GetMembers Dim Iterator As MemberInfo For Each Iterator In ObjectMembers Debug.WriteLine(Iterator.Name) Debug.WriteLine(Iterator.ReflectedType.ToString) Next |
| BroadCaster bc = new BroadCaster(); Type t = typeof(c); MemberInfo[] ObjectMembers = t.GetMembers(); foreach(MemberInfo m in ObjectMembers) { Debug.WriteLine(m.Name); Debug.WriteLine(m.ReflectedType.ToString()); } |
