1. Reflection is based on Sytem.type, and many of the methods inside are System.Reflection .
MethodInfo[] tt= t.GetType().GetMethods(); //t是string的实例,获得string类型的所有方法,这里面的GetMethods有个BindingFlags枚举类型,写了很多 常用的需要的类
foreach (var item in tt) {
Console.WriteLine(item.ToString());
}
Console.ReadKey();
2. Assembly-based reflection
assembly = assembly load "mscorlib,2.0.0.0.0,b77acu87d987asdf98" //the token value here is casually written
type Span class= "pun" >[] types = objassembly gettypes
Assembly objAss = Assembly.GetExecutingAssembly();
Type t = objAss.GetType("Reflection.car", false, true);//第一个false表示找不到时不引发异常,第二个true表示忽略大小写查找
Span class= "Typ" >car oo = ( car activator Span class= "pun". createinstance t //creates an instance of a class based on the established type, because it is not until what is returned, so covarince is an object
Span class= "Typ" >methodinfo mi = T getmethod "move" //move is the method name in the car class
var ismove = (bool)mi.Invoke(oo, null); // 调用MethodInfo的方法Invoke,核实方法move是不是在类oo中
if (ismove) {
Console.WriteLine("is move ");
}
one of the car is a class, the 3rd behavior I modified after the code, the original code directly for object, not too rigorous, although can also use, but so write more dead some
Where assembly usage refer to other pages
From for notes (Wiz)
C#-reflection Knowledge points