Define Reflection?
Reflection is the feature in .NET, which allows to get some information about object in runtime. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that object.
To write a C#.NET program which uses the reflection, the program should use the namespace System.Reflection.
· To get the object type or the class name of our object, the typeof operator can be used.
· GetType() method can be used for retrieving the type information of a class or to get the data about objects
In addition to reading the types defined within a given assembly, you can also generate (emit) your own assemblies and types using the services of System.Reflection.Emit or System.CodeDom.
What is Reflection?
A compiler for the common language runtime (CLR) will generate metadata during compilation and store the metadata (in a binary format) directly into assemblies and modules to avoid irregularities.
Reflection is the ability to read metadata at runtime. Reflection is a collection of classes, which allow you to query assembly (classes/objects) metadata at runtime (ability to read metadata at runtime). Using reflection you can also create new types and their instances at runtime and invoke methods on these new type instances.
There are other uses for reflection. Compilers for languages such as JScript use reflection to construct symbol tables.
Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. Reflection also allows us to create new types at runtime.
Reflection generally begins with a call to a method present on every object in the .NET framework: GetType. The GetType method is a member of the System.Object class, and the method returns an instance of System.Type. System.Type is the primary gateway to metadata. System.Type is actually derived from another important class for reflection: the MemeberInfo class from the System.Reflection namespace. MemberInfo is a base class for many other classes who describe the properties and methods of an object, including FieldInfo, MethodInfo, ConstructorInfo, ParameterInfo, and EventInfo among others. As you might suspect from their names, you can use these classes to inspect different aspects of an object at runtime.
When reflection is useful in any application?
Reflection package is used in an application of you want to know the methods, variables, used in the class.
What is reflection in Microsoft.NET Context?
The REFLECTION is used to read the metadata information like (type, reference and methods). Which is derived from system.assembly.reflection class object.
The simple meaning is to read assembly information by using this system.assembly.reflection class.
How do you retrieve attributes on classes and methods defined within an assembly?
Using Reflections.
What is the tool that uses reflection to inspect assemblies?
Reflector tool uses reflection to inspect assemblies. All the classes derive from System.Attribute namespace.
What is Reflection in .NET? Namespace? How will you load an assembly which is not referenced by current assembly? All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly.Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for marshaling data across context/process/machine boundaries.Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).
Reflection
Assemblies store metadata, including details of all the types and members of these types that are defined in the assembly. This technique is known as reflection.
Monday, May 21, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment