<bdo id='pAZ1r'></bdo><ul id='pAZ1r'></ul>

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

      <legend id='pAZ1r'><style id='pAZ1r'><dir id='pAZ1r'><q id='pAZ1r'></q></dir></style></legend>

    2. <small id='pAZ1r'></small><noframes id='pAZ1r'>

      以编程方式将属性添加到方法或参数

      Programmatically add an attribute to a method or parameter(以编程方式将属性添加到方法或参数)

      <tfoot id='0yLMI'></tfoot>

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

            <legend id='0yLMI'><style id='0yLMI'><dir id='0yLMI'><q id='0yLMI'></q></dir></style></legend>

              <small id='0yLMI'></small><noframes id='0yLMI'>

                  <tbody id='0yLMI'></tbody>
                本文介绍了以编程方式将属性添加到方法或参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我可以使用 TypeDescriptor.AddAttributes 在运行时向类型添加属性.如何对方法和参数执行相同操作?(可能是 2 个单独的问题...)

                I can use TypeDescriptor.AddAttributes to add an attribute to a type in runtime. How do I do the same for a method and parameter? (maybe 2 separate questions...)

                推荐答案

                TypeDescriptor.AddAttributes 只影响非常特定的用例;即来自 System.ComponentModel.对于反射的rest,它对额外的属性一无所知.事实上,System.ComponentModel 并不真正适用于方法或参数.

                TypeDescriptor.AddAttributes only affects a very specific use-case; i.e. from within System.ComponentModel. For the rest of reflection, it knows nothing about the extra attribute. And indeed, System.ComponentModel doesn't really apply to methods or parameters.

                简而言之;你不能.您需要将此信息存储在其他地方(定制),或在编译时添加.

                So in short; you can't. You will need to store this information somewhere else (bespoke), or add it at compile-time.

                这篇关于以编程方式将属性添加到方法或参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

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

                • <i id='9gxBC'><tr id='9gxBC'><dt id='9gxBC'><q id='9gxBC'><span id='9gxBC'><b id='9gxBC'><form id='9gxBC'><ins id='9gxBC'></ins><ul id='9gxBC'></ul><sub id='9gxBC'></sub></form><legend id='9gxBC'></legend><bdo id='9gxBC'><pre id='9gxBC'><center id='9gxBC'></center></pre></bdo></b><th id='9gxBC'></th></span></q></dt></tr></i><div id='9gxBC'><tfoot id='9gxBC'></tfoot><dl id='9gxBC'><fieldset id='9gxBC'></fieldset></dl></div>
                      <tbody id='9gxBC'></tbody>
                    • <small id='9gxBC'></small><noframes id='9gxBC'>

                      1. <tfoot id='9gxBC'></tfoot>
                        <legend id='9gxBC'><style id='9gxBC'><dir id='9gxBC'><q id='9gxBC'></q></dir></style></legend>
                          <bdo id='9gxBC'></bdo><ul id='9gxBC'></ul>