• <legend id='DkVbA'><style id='DkVbA'><dir id='DkVbA'><q id='DkVbA'></q></dir></style></legend>

      • <bdo id='DkVbA'></bdo><ul id='DkVbA'></ul>

      1. <tfoot id='DkVbA'></tfoot>
      2. <small id='DkVbA'></small><noframes id='DkVbA'>

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

        获取描述属性在类级别

        Get the description attributes At class level(获取描述属性在类级别)

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

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

                <tfoot id='ztBmp'></tfoot>
                <i id='ztBmp'><tr id='ztBmp'><dt id='ztBmp'><q id='ztBmp'><span id='ztBmp'><b id='ztBmp'><form id='ztBmp'><ins id='ztBmp'></ins><ul id='ztBmp'></ul><sub id='ztBmp'></sub></form><legend id='ztBmp'></legend><bdo id='ztBmp'><pre id='ztBmp'><center id='ztBmp'></center></pre></bdo></b><th id='ztBmp'></th></span></q></dt></tr></i><div id='ztBmp'><tfoot id='ztBmp'></tfoot><dl id='ztBmp'><fieldset id='ztBmp'></fieldset></dl></div>
                  本文介绍了获取描述属性在类级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这样的课

                  [Description("This is a wahala class")]
                  public class Wahala
                  {
                  
                  }
                  

                  有没有办法获取Wahala类的Description属性的内容?

                  Is there anyway to get the content of the Description attribute for the Wahala class?

                  推荐答案

                  绝对 - 使用 Type.GetCustomAttributes.示例代码:

                  Absolutely - use Type.GetCustomAttributes. Sample code:

                  using System;
                  using System.ComponentModel;
                  
                  [Description("This is a wahala class")]
                  public class Wahala
                  {    
                  }
                  
                  public class Test
                  {
                      static void Main()
                      {
                          Console.WriteLine(GetDescription(typeof(Wahala)));
                      }
                  
                      static string GetDescription(Type type)
                      {
                          var descriptions = (DescriptionAttribute[])
                              type.GetCustomAttributes(typeof(DescriptionAttribute), false);
                  
                          if (descriptions.Length == 0)
                          {
                              return null;
                          }
                          return descriptions[0].Description;
                      }
                  }
                  

                  同种代码可以检索其他成员的描述,例如字段、属性等.

                  The same kind of code can retrieve descriptions for other members, such as fields, properties etc.

                  这篇关于获取描述属性在类级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                    <bdo id='qRhPV'></bdo><ul id='qRhPV'></ul>

                      <tfoot id='qRhPV'></tfoot>

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

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

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