<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. 仅在特定类型上允许自定义属性

        Allow a custom Attribute only on specific type(仅在特定类型上允许自定义属性)
          <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).

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

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

                  相关文档推荐

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

                              <tbody id='gVUb0'></tbody>