C# Refresh
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Reflection using C#
Reflection as word means something like consideration of some subject matter, or the return of light or sound waves from a surface.
In relation to code is it when managed code reads its codes metadata to retrieve extended information, this is in C# done by providing objects (of type Type) that describe assemblies, modules, and types.
You can among other use reflection to:
- obtain type information
- get information of an assembly
- build new types at runtime
- performing late binding
We are going use reflection working with attributes.
Simple example on reflection
1
2
3
4
5
6
7
8
9
10
11
using System;
class Program{
static void Main()
{
int i = 42;
Type type = i.GetType();
Console.WriteLine(type);
}
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content