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

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

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

        <bdo id='RidIi'></bdo><ul id='RidIi'></ul>
      1. 仅在特定类型上允许自定义属性

        时间:2023-07-27
          <bdo id='rqLZu'></bdo><ul id='rqLZu'></ul>
        • <legend id='rqLZu'><style id='rqLZu'><dir id='rqLZu'><q id='rqLZu'></q></dir></style></legend>

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

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

              <tbody id='rqLZu'></tbody>

                  <tfoot id='rqLZu'></tfoot>
                1. 本文介绍了仅在特定类型上允许自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法强制编译器将自定义属性的使用限制为仅用于特定的 property 类型,如 int、short、string(所有原始类型)?
                  类似于 AttributeUsageAttribute 的 ValidOn-AttributeTargets 枚举.

                  Is there a way to force the compiler to restrict the usage of a custom attribute to be used only on specific property types like int, short, string (all the primitive types)?
                  similar to the AttributeUsageAttribute's ValidOn-AttributeTargets enumeration.

                  推荐答案

                  不,你不能,基本上.您可以将其限制为 struct vs class vs interface,仅此而已.另外:无论如何,您都不能向代码之外的类型添加属性(通过 TypeDescriptor 除外,这不一样).

                  No, you can't, basically. You can limit it to struct vs class vs interface, that is about it. Plus: you can't add attributes to types outside your code anyway (except for via TypeDescriptor, which isn't the same).

                  这篇关于仅在特定类型上允许自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:以编程方式隐藏 PropertyGrid 中的字段 下一篇:GetCustomAttributes() 是否保留 .NET 中的属性顺序?

                  相关文章

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

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

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

                      <bdo id='gVUb0'></bdo><ul id='gVUb0'></ul>
                    <tfoot id='gVUb0'></tfoot>