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

      • <bdo id='iGjAe'></bdo><ul id='iGjAe'></ul>
      <legend id='iGjAe'><style id='iGjAe'><dir id='iGjAe'><q id='iGjAe'></q></dir></style></legend>
      1. <tfoot id='iGjAe'></tfoot>
      2. C# Attributes 强制属性

        C# Attributes mandatory property(C# Attributes 强制属性)

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

                <tfoot id='w63DF'></tfoot>

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

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

                • 本文介绍了C# Attributes 强制属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经创建了类似

                      [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
                      [Serializable]
                      public class TestPropertyAttribute : System.Attribute
                      {
                          public string Name
                          {
                              get { return _name; }
                              set { _name = value; }
                          }string _name;
                      }
                  

                  我应该将名称"标记为该属性的强制属性.怎么做?

                  and I should mark "Name" as mandatory property of this attribute. How to do it?

                  推荐答案

                  把它放在构造函数中,而不是仅仅作为一个单独的属性:

                  Put it in the constructor instead of just as a separate property:

                  [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
                  [Serializable]
                  public class TestPropertyAttribute : System.Attribute
                  {
                      readonly string _name;
                  
                      public TestPropertyAttribute(string name)
                      {
                          _name = name;
                      }
                  
                      public string Name { get { return _name; } }
                  }
                  

                  我不相信你可以强制并且在应用属性时使用 Name=... 语法.

                  I don't believe you can make it mandatory and use the Name=... syntax when applying the attribute though.

                  这篇关于C# Attributes 强制属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的代码生成属性相关联)
                  <tfoot id='dxBs4'></tfoot>
                • <small id='dxBs4'></small><noframes id='dxBs4'>

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

                          <tbody id='dxBs4'></tbody>

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