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

    1. <small id='Bys6S'></small><noframes id='Bys6S'>

      <i id='Bys6S'><tr id='Bys6S'><dt id='Bys6S'><q id='Bys6S'><span id='Bys6S'><b id='Bys6S'><form id='Bys6S'><ins id='Bys6S'></ins><ul id='Bys6S'></ul><sub id='Bys6S'></sub></form><legend id='Bys6S'></legend><bdo id='Bys6S'><pre id='Bys6S'><center id='Bys6S'></center></pre></bdo></b><th id='Bys6S'></th></span></q></dt></tr></i><div id='Bys6S'><tfoot id='Bys6S'></tfoot><dl id='Bys6S'><fieldset id='Bys6S'></fieldset></dl></div>
      <tfoot id='Bys6S'></tfoot>
        <bdo id='Bys6S'></bdo><ul id='Bys6S'></ul>
    2. 将 Class 的实例作为参数传递给 Attribute 构造函数

      时间:2023-07-26
        <tbody id='Uh05u'></tbody>

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

          1. <legend id='Uh05u'><style id='Uh05u'><dir id='Uh05u'><q id='Uh05u'></q></dir></style></legend>

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

                <bdo id='Uh05u'></bdo><ul id='Uh05u'></ul>
                本文介绍了将 Class 的实例作为参数传递给 Attribute 构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要自定义属性中的类/模型实例(用于访问非静态成员).

                I need an instance of class/model(for the purpose of accessing a non-static member) within my custom attribute.

                public class LoginModel
                {
                     [AutoComplete(currentInstance)]  //pass instance of class or CompanyNames
                     public string DepartmentName { get; set; }
                
                
                     public string[] DepartmentNames { get {...} }
                }
                

                有没有办法在不使用 new() 或反射的情况下做到这一点.

                Is there a way to do this without using new() or Reflection.

                推荐答案

                这完全不可能.属性在编译时被烘焙到程序集的元数据中,因此谈论将类的实例传递给属性没有任何意义,因为实例仅在运行时存在.

                That's totally impossible. Attributes are baked into the metadata of the assembly at compile-time so talking about passing an instance of a class to an attribute doesn't make any sense because instances exist only at runtime.

                另一方面,属性总是被反射消耗掉,所以我猜现在您正在检查类元数据上是否存在此自定义属性,您可以使用该实例.

                On the other hand attributes are always consumed by reflection, so I guess that at the moment you are checking for the presence of this custom attribute on the class metadata you could use the the instance.

                这篇关于将 Class 的实例作为参数传递给 Attribute 构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:.net XmlSerializer 上覆盖的属性 下一篇:如何使 .NET 属性仅对某些类型有效

                相关文章

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

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

                  2. <tfoot id='zfp6f'></tfoot>