Reflection is the process of describing the metadata of types, methods, and fields in a code. It enables a program to analyze the structure of some code and change the effective behavior of the code. In C#, reflection allows us to inspect and manipulate classes, constructors, methods, and fields at runtime. However, C does not have reflection built-in at all.
The namespace System.Reflection in C# enables obtaining data about the loaded assemblies, the elements within them like classes, methods, and value types. The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application. The primary way to access reflection in C# is through the Type class.
Some of the commonly used classes of System.Reflection are:
- Assembly
- Module
- Enum
- MethodInfo
- ConstructorInfo
- MemberInfo
- ParameterInfo
- Type
- FieldInfo
- EventInfo
- PropertyInfo
Reflection has several applications, including viewing attribute information at runtime, examining various types in an assembly and instantiating these types, late binding to methods and properties, and creating new types at runtime and then performing some tasks using those types.
In summary, reflection in C is not supported, while in C#, it allows inspecting and manipulating classes, constructors, methods, and fields at runtime through the System.Reflection namespace and the Type class.