1. <small id='S4Q8c'></small><noframes id='S4Q8c'>

      <tfoot id='S4Q8c'></tfoot>
        <bdo id='S4Q8c'></bdo><ul id='S4Q8c'></ul>
      <i id='S4Q8c'><tr id='S4Q8c'><dt id='S4Q8c'><q id='S4Q8c'><span id='S4Q8c'><b id='S4Q8c'><form id='S4Q8c'><ins id='S4Q8c'></ins><ul id='S4Q8c'></ul><sub id='S4Q8c'></sub></form><legend id='S4Q8c'></legend><bdo id='S4Q8c'><pre id='S4Q8c'><center id='S4Q8c'></center></pre></bdo></b><th id='S4Q8c'></th></span></q></dt></tr></i><div id='S4Q8c'><tfoot id='S4Q8c'></tfoot><dl id='S4Q8c'><fieldset id='S4Q8c'></fieldset></dl></div>
      <legend id='S4Q8c'><style id='S4Q8c'><dir id='S4Q8c'><q id='S4Q8c'></q></dir></style></legend>

        我将如何使用反射来调用具有某个自定义属性的所有方法?

        时间:2023-07-27
        <tfoot id='dAczd'></tfoot>

          1. <i id='dAczd'><tr id='dAczd'><dt id='dAczd'><q id='dAczd'><span id='dAczd'><b id='dAczd'><form id='dAczd'><ins id='dAczd'></ins><ul id='dAczd'></ul><sub id='dAczd'></sub></form><legend id='dAczd'></legend><bdo id='dAczd'><pre id='dAczd'><center id='dAczd'></center></pre></bdo></b><th id='dAczd'></th></span></q></dt></tr></i><div id='dAczd'><tfoot id='dAczd'></tfoot><dl id='dAczd'><fieldset id='dAczd'></fieldset></dl></div>

              <tbody id='dAczd'></tbody>

          2. <legend id='dAczd'><style id='dAczd'><dir id='dAczd'><q id='dAczd'></q></dir></style></legend>

            <small id='dAczd'></small><noframes id='dAczd'>

              <bdo id='dAczd'></bdo><ul id='dAczd'></ul>
                • 本文介绍了我将如何使用反射来调用具有某个自定义属性的所有方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含一堆方法的类.

                  I have a class with a bunch of methods.

                  其中一些方法由自定义属性标记.

                  some of these methods are marked by a custom attribute.

                  我想一次调用所有这些方法.

                  I would like to call all these methods at once.

                  我将如何使用反射来查找该类中包含此属性的所有方法的列表?

                  How would I go about using reflection to find a list of all the methods in that class that contains this attribute?

                  推荐答案

                  获得方法列表后,您将使用 GetCustomAttributes 方法循环查询自定义属性.您可能需要更改 BindingFlags 以适应您的情况.

                  Once you get the list of methods, you would cycle query for the custom attributes using the GetCustomAttributes method. You may need to change the BindingFlags to suit your situation.

                  var methods = typeof( MyClass ).GetMethods( BindingFlags.Public );
                  
                  foreach(var method in methods)
                  {
                      var attributes = method.GetCustomAttributes( typeof( MyAttribute ), true );
                      if (attributes != null && attributes.Length > 0)
                          //method has attribute.
                  
                  }
                  

                  这篇关于我将如何使用反射来调用具有某个自定义属性的所有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:方括号之间的文字含义 下一篇:在 C# 中组合多个属性

                  相关文章

                      <small id='XyOwr'></small><noframes id='XyOwr'>

                      • <bdo id='XyOwr'></bdo><ul id='XyOwr'></ul>

                    1. <legend id='XyOwr'><style id='XyOwr'><dir id='XyOwr'><q id='XyOwr'></q></dir></style></legend><tfoot id='XyOwr'></tfoot>

                    2. <i id='XyOwr'><tr id='XyOwr'><dt id='XyOwr'><q id='XyOwr'><span id='XyOwr'><b id='XyOwr'><form id='XyOwr'><ins id='XyOwr'></ins><ul id='XyOwr'></ul><sub id='XyOwr'></sub></form><legend id='XyOwr'></legend><bdo id='XyOwr'><pre id='XyOwr'><center id='XyOwr'></center></pre></bdo></b><th id='XyOwr'></th></span></q></dt></tr></i><div id='XyOwr'><tfoot id='XyOwr'></tfoot><dl id='XyOwr'><fieldset id='XyOwr'></fieldset></dl></div>