Reflection
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Reflection provides objects that encapsulate assemblies, modules, and types. In Silverlight, as in other versions of the .NET Framework, you can use reflection to determine the type and members of an unknown object and to invoke the accessible members. You can use reflection to explore the types available in an assembly, to dynamically create an instance of a type, and to invoke the accessible methods, fields, and properties of the instance; however, in Silverlight reflection cannot be used to bypass access level restrictions and (for example) invoke private members.
The classes in the System.Reflection namespace, used with System.Type, support reflection. The following table describes typical uses of these classes.
Class |
Typical uses |
How to obtain |
---|---|---|
Load assemblies, locate types in assemblies. |
||
Locate types in modules, resolve metadata tokens. |
||
Invoke members. Discover attributes, access modifiers, nesting, members. |
Assembly.GetTypes, Module.GetTypes, GetType, Assembly.GetType |
|
Invoke (to create objects). Discover attributes, parameters, access modifiers. |
||
Invoke. Discover attributes, parameters, access modifiers. |
||
Get or set values. Discover attributes, parameters, access modifiers. |
||
Hook up events. Discover attributes, parameters, access modifiers. |
||
Get or set values. Discover attributes, index parameters, access modifiers, read/write. |
||
Discover type, position, ref/out. |
MethodBuilder.GetParameters, ConstructorBuilder.GetParameters |
The classes of the System.Reflection.Emit namespace provide a specialized form of reflection that enables you to build types and dynamic methods at run time.
Reflection can be used to create applications called type browsers, which enable users to select types and then view the information about those types.
In This Section
Topic |
Description |
---|---|
Describes the internal types, such as RuntimeType, that inherit the abstract classes in the System.Reflection namespace and provide much of their implementation. |
|
Describes the System.Type class and provides code examples that illustrate how to use System.Type with several reflection classes to obtain information about constructors, methods, fields, properties, and events. |
|
Explains how reflection handles the type parameters and type arguments of generic types and generic methods. |
|
Provides a table showing the method naming pattern of the most frequently used reflection classes, such as the Module, Type, and MemberInfo classes. |
|
Describes the rules that determine to what degree reflection can be used to discover type information and access the members of types. |
|
Describes the reflection custom-binding interface that supports late binding. |
|
Demonstrates how to use reflection to access default members that a class might have. |
|
Demonstrates how to use reflection to query attribute existence and values. |
|
Describes the format of fully qualified type names in Backus-Naur form (BNF), and the syntax required for specifying special characters, assembly names, pointers, references, and arrays. |
|
Explains how to create a delegate for a method and hook the delegate up to an event. Explains how to create an event-handling method at run time using DynamicMethod. |
Reference
Topic |
Description |
---|---|
The class that represents types in the runtime type system and provides core functionality for reflection. |
|
The namespace that contains other abstractions for code entities, such as the MethodInfo class that represents methods. |
|
The namespace that contains classes for generating dynamic assemblies and dynamic methods. |
Related Sections
Topic |
Description |
---|---|
Describes the types in the System.Reflection.Emit namespace that enable an application to emit metadata and Microsoft intermediate language (MSIL) at run time. |