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 强制属性

        时间:2023-07-26

        <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 强制属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 IsDefined 而不是 GetCustomAttributes 有什么好处吗 下一篇:面板没有得到焦点

                  相关文章

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

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