通过学习反射了解反射应用的场景有如下几个方面:  动态生成类型实例、动态调用成员(方法/属性)、动态指定参数、后期加载、绑定、工厂模式。
主要的成员有:
Assembly、Type、MemberInfo、EventInfo、ParameterInfo、FieldInfo等。我们可以通过foreach语句来迭代**Info中的具体值。例如:

            //Type stringType = typeof(string);

            //Console.WriteLine("The public constructor of string are:");
            //foreach (ConstructorInfo item in stringType.GetConstructors())
            //{
            //    if (item!=null)
            //    {
            //        Console.WriteLine(item.ToString());
            //    }

就可以完成构建函数的枚举。
当然需要System.Reflection命名空间。还有MSDN中一个非常好的代码例子:ms-help://MS.MSDNQTR.v90.chs/fxref_mscorlib/html/7e1337f8-5ea2-2a48-8a74-37315ae74f0a.htm

相关文章:

  • 2021-06-08
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2022-01-17
猜你喜欢
  • 2021-10-11
  • 2021-10-22
  • 2021-12-06
  • 2021-11-04
  • 2021-06-14
  • 2021-12-27
相关资源
相似解决方案