SoFunction
Updated on 2025-03-04

Some applications of C# reflection

I am also unfamiliar with reflexes, so I took a look at the reflexes and took notes when I had time! ! !
Definition of reflection: Reflection is an important mechanism in .NET. Through radiation, members of each type in .NET (including classes, structures, delegates, interfaces, enums, etc.) can be obtained at runtime, including methods, attributes, events, and constructors. You can also obtain the name, qualifiers, parameters, etc. of each member. With reflection, you can know every type well. If you obtain the constructor information, you can create the object directly, even if the type of this object is not known at compile time.
1. Import using;
2. ("assembly")//("Dynamic Library for External Calls") Loading the assembly, the return type is an Assembly
  3,   foreach (Type type in ())
            {
                string t = ;
            }
Get the names of all classes in the assembly
4,Type type = ("assembly.class name"); get the type of the current class
5,(type); Create an instance of this type
6,MethodInfo mInfo = ("Methodname"); Get the current method
7,(null, method parameters);
These are some basic applications of reflection,