<tfoot id='raIpz'></tfoot>

      <legend id='raIpz'><style id='raIpz'><dir id='raIpz'><q id='raIpz'></q></dir></style></legend>
        • <bdo id='raIpz'></bdo><ul id='raIpz'></ul>

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

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

        读取方法的属性值

        Read the value of an attribute of a method(读取方法的属性值)
          <bdo id='vuSpb'></bdo><ul id='vuSpb'></ul>

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

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

          <tfoot id='vuSpb'></tfoot>

                  <tbody id='vuSpb'></tbody>
                • 本文介绍了读取方法的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要能够从我的方法中读取我的属性值,我该怎么做?

                  I need to be able to read the value of my attribute from within my Method, how can I do that?

                  [MyAttribute("Hello World")]
                  public void MyMethod()
                  {
                      // Need to read the MyAttribute attribute and get its value
                  }
                  

                  推荐答案

                  你需要调用MethodBase 对象上的 noreferrer">GetCustomAttributes 函数.
                  获取 MethodBase 对象的最简单方法是调用 MethodBase.GetCurrentMethod.(注意要加上[MethodImpl(MethodImplOptions.NoInlining)])

                  You need to call the GetCustomAttributes function on a MethodBase object.
                  The simplest way to get the MethodBase object is to call MethodBase.GetCurrentMethod. (Note that you should add [MethodImpl(MethodImplOptions.NoInlining)])

                  例如:

                  MethodBase method = MethodBase.GetCurrentMethod();
                  MyAttribute attr = (MyAttribute)method.GetCustomAttributes(typeof(MyAttribute), true)[0] ;
                  string value = attr.Value;    //Assumes that MyAttribute has a property called Value
                  

                  你也可以手动获取MethodBase,像这样:(这样会更快)

                  You can also get the MethodBase manually, like this: (This will be faster)

                  MethodBase method = typeof(MyClass).GetMethod("MyMethod");
                  

                  这篇关于读取方法的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的代码生成属性相关联)

                    <tbody id='p8OEG'></tbody>

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

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

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