反射(Reflection)让程序能够在运行时检查和操作类型、方法以及属性——甚至包括编译时未知的那些。特性(Attributes)则为代码附加声明式的元数据(metadata),工具和框架会读取这些元数据(通常通过反射)来驱动行为。两者结合,支撑起了 .NET 框架中大量的“魔法”(序列化、依赖注入、ORM、验证)。
反射——运行时检查与调用
Type type = (User);
(PropertyInfo prop type.GetProperties())
Console.WriteLine();
(MethodInfo method type.GetMethods()) { }
instance = Activator.CreateInstance(type);
PropertyInfo p = type.GetProperty();
p.SetValue(instance, );
