<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>

        读取方法的属性值

        时间:2023-07-27
          <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");
                  

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

                  上一篇:从枚举属性中获取枚举 下一篇:继承如何对属性起作用?

                  相关文章

                  <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>
                  1. <legend id='p8OEG'><style id='p8OEG'><dir id='p8OEG'><q id='p8OEG'></q></dir></style></legend>

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