2. What is reflection
Definition - to look back to itself
• Fields Run Time Type Information
• Methods Discovering class information
solely at run time
• Properties
.net Reflection
Assembly Access based on
metadata
3. System.Type
• Base of all reflection classes and properties -
primary way to access metadata
– Represents all kinds of types (class, interface,
enumeration…)
• GetType() is a Method of System.Object
• typeof() operator returns Type object
• A Type is unique per type
• Only one instance of Type per type per
application domain
4. MemberInfo class
• Provides access to member metadata.
• MemberType propery is useful to
determine the tipe of a member
• Ancestor to all other XXXInfo classes
• Actually an ancestor to Type
6. Attributes
• An information which marks the
elements of code.
• A class that derives from
System.Attribute
• Multiple points of consumption –
compiler, CLR, debugger, user code
• Can use both positional and named
parameters
7. Using Custom Attributes
• Type.GetCustomAttributes
• Attribute.GetCustomAttribute
• Only way to get information about
attributes applied to an object in user
code
11. Speed of Reflecting
• As expected, direct access is much
faster than reflection
• Performance hit – anywhere from 5 to
150 times slower
• Avoid using lots of reflection in tight
loops
• We should weight if the usefulness in
the scenario justifies the slowdown.
12. References
• Generics Terminology in .NET Framework -
http://blogs.msdn.com/parthopdas/archive/2005/10/21/483463.aspx
• Hello World.Emit -
http://blogs.msdn.com/joelpob/archive/2004/01/21/61411.aspx
• Programming C#: Attributes and Reflection -
http://www.ondotnet.com/pub/a/dotnet/excerpt/prog_csharp_ch18/index.html
?page=1
• How Microsoft Uses Reflection - http://msdn2.microsoft.com/en-
us/magazine/cc163960.aspx
• Real-world Reflection in .NET -
http://www.devx.com/dotnet/Article/31578/1954
• Reflection - Dodge Common Performance Pitfalls
http://msdn2.microsoft.com/en-us/magazine/cc163759.aspx
• .NET Reflection: Dynamically Bind Your Data Layer
-http://msdn.microsoft.com/msdnmag/issues/02/08/NETReflection/default.as
px
• And many others