xxxxxxxxxx
Reflection is a mechanism that allows us to write code that can
inspect types used in the application. For example, using reflection, we can
list all fields and their values belonging to a given object, even if at
compile time we don’t know what type it is exactly.
For more details:
https://www.javatpoint.com/c-sharp-reflection
xxxxxxxxxx
/*Reflection is a feature in the C# programming language that allows code to
inspect itself at runtime. This means that a program can access its own
metadata, such as the types, properties, and methods of objects, and use that
information to modify its own behavior.
*/
int i = 42;
System.Type type = i.GetType();
System.Console.WriteLine(type);
// Result
System.Int32
xxxxxxxxxx
//// Get name of type
Type MyType = Type.GetType("System.Collections.ArrayList");
//Store all the tpyes
MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
//Display
foreach (MemberInfo item in Mymemberinfoarray)
{
richTextBox1.AppendText(item.Name + " (" + item.MemberType + ") \n");
}