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>

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

        How would I use reflection to call all the methods that has a certain custom attribute?(我将如何使用反射来调用具有某个自定义属性的所有方法?)
        <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.
                  
                  }
                  

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)

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

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

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

                              <tbody id='XyOwr'></tbody>
                            <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>