none
怎样枚举ManagementObject.InvokeMethod所能调用的所有方法名 RRS feed

全部回复

  • Hi sincos,

    你可以使用ManagementClass.Methods 属性来获得所有能调用的方法名。

    具体代码如下:

     using (ManagementClass processClass = new ManagementClass("Win32_Process"))
                    foreach (MethodData method in processClass.Methods)
                    {
                        bool isStatic = method.Qualifiers
                            .Cast<QualifierData>()
                            .Any(qualifier => string.Equals(qualifier.Name, "Static", StringComparison.OrdinalIgnoreCase));
    
                        Console.WriteLine($"{method.Origin}.{method.Name}() [{(isStatic ? "static" : "instance")}]");
                      
                    }

    结果:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2020年7月13日 8:40
    版主