【问题标题】:Is there a way to see all methods available to a given class instance in C#? [duplicate]有没有办法在 C# 中查看给定类实例可用的所有方法? [复制]
【发布时间】:2017-10-06 18:23:47
【问题描述】:

在 python 中,我可以轻松地查看re 模块的所有方法:

   >>> import re
   >>> dir(re)
   ['DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'S', 'Scanner', 'T', 'TEMPLATE', 'U', 'UNICODE', 'VERBOSE', 'X', '_MAXCACHE', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_alphanum', '_cache', '_cache_repl', '_compile', '_compile_repl', '_expand', '_locale', '_pattern_type', '_pickle', '_subx', 'compile', 'copy_reg', 'error', 'escape', 'findall', 'finditer', 'match', 'purge', 'search', 'split', 'sre_compile', 'sre_parse', 'sub', 'subn', 'sys', 'template']

我可以对给定类的任何实例做同样的事情。 C# 可以做到这一点吗?

【问题讨论】:

  • 如果您只想在编程时执行此操作,请键入“re”。 -- intellisense 会在点后弹出成员列表。

标签: c# python


【解决方案1】:

是的,您可以为此目的使用反射并使用 GetMethods() 之类的函数

(typeof(yourclass)).GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);

【讨论】:

    【解决方案2】:

    【讨论】:

    • 为什么投反对票?我讨厌没有 cmets 的投票。
    猜你喜欢
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 2014-11-24
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    相关资源
    最近更新 更多