简体   繁体   English

C#反射汇编:getMethods()忽略构造函数

[英]C# Reflection Assembly: getMethods() ignores constructors

As said in title. 如标题中所述。 I tried using Bindingflags but none of them seem to be working: 我尝试使用Bindingflags,但它们似乎都不起作用:

Assembly assembly = Assembly.LoadFile(somePath);
foreach (var type in assembly.GetTypes())
            {
             foreach(var method in type.GetMethods())
             Console.WriteLine(method.Name);
            }

That's because constructors are not methods (despite some superficial similarities in syntax). 这是因为构造函数不是方法(尽管语法上存在一些肤浅的相似之处)。 For constructors you want Type.GetConstructors ( http://msdn.microsoft.com/en-us/library/vstudio/system.type.getconstructors ). 对于构造函数,您需要Type.GetConstructorshttp://msdn.microsoft.com/zh-cn/library/vstudio/system.type.getconstructors )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM