.Net Runtime Library for Delphi
Close
Reflection

The reflection interfaces are defined in CNClrLib.Core or CNClrLib.Core.Intf namespace which enables you to obtain information about loaded .net assemblies and the types defined within them, such as classes, interfaces, and value types. You can also use reflection to create type instances at run time, and to invoke and access them.

The runtime library starts the common language runtime and the common language runtime loader manages application domains, which constitute defined boundaries around objects that have the same application scope. This management includes loading each assembly into the appropriate application domain and controlling the memory layout of the type hierarchy within each assembly.

Assemblies contain modules, modules contain types, and types contain members. Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object. You can then invoke the type's methods or access its fields and properties.

Typical uses of reflection include the following:

  • Use _Assembly interface or TClrAssembly Classto define and load assemblies, load modules that are listed in the assembly manifest, and locate a type from this assembly and create an instance of it.
  • Use _Module interface to discover information such as the assembly that contains the module and the classes in the module. You can also get all global methods or other specific, nonglobal methods defined on the module.
  • Use _ConstructorInfo interface to discover information such as the name, parameters, access modifiers (such as public or private), and implementation details (such as abstract or virtual) of a constructor. Use the GetConstructors or GetConstructor method of a _Type to invoke a specific constructor.
  • Use _MethodInfo interface to discover information such as the name, return type, parameters, access modifiers (such as public or private), and implementation details (such as abstract or virtual) of a method. Use the GetMethods or GetMethod method of a _Type to invoke a specific method.
  • Use _FieldInfo interface to discover information such as the name, access modifiers (such as public or private) and implementation details (such as static) of a field, and to get or set field values.
  • Use _EventInfo interface to discover information such as the name, event-handler data type, custom attributes, declaring type, and reflected type of an event, and to add or remove event handlers.
  • Use _PropertyInfo interface to discover information such as the name, data type, declaring type, reflected type, and read-only or writable status of a property, and to get or set property values.
  • Use _ParameterInfo interface to discover information such as a parameter's name, data type, whether a parameter is an input or output parameter, and the position of the parameter in a method signature.
  • Use _CustomAttributeData interface to discover information about custom attributes when you are working in the reflection-only context of an application domain. It allows you to examine attributes without creating instances of them.

There are other interfaces in the above namespace which provides a specialized form of reflection that enables you to build types at runtime.

 

 

Related Topics

Viewing Type Information

Describes the _Type interface and provides code examples that illustrate how to use Type with several reflection classes to obtain information about constructors, methods, fields, properties, and events.

How to: Examine and Instantiate Generic Types with Reflection

Explains how reflection handles the type parameters and type arguments of generic types and generic methods.

Accessing Custom Attributes

Demonstrates using reflection to query attribute existence and values.

How to: Hook Up a Delegate Using Reflection

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.

Reflection Using ClrObject

Explains how to use ClrObject interface to smoothly access the fields and properties, trigger the events and invoke the methods of object the interface is wrapping.