首頁  >  文章  >  後端開發  >  C# 中的 System.Reflection.Module 是什麼?

C# 中的 System.Reflection.Module 是什麼?

PHPz
PHPz轉載
2023-09-12 21:33:03807瀏覽

C# 中的 System.Reflection.Module 是什么?

System.Reflection 命名空間包含的類別可讓您取得有關應用程式的信息,並向應用程式動態新增類型、值和物件。

它有一個模組建構函數,用來初始化Module 類別的新實例。模組是一種可移植的可執行文件,具有一個或多個類別和介面。

讓我們來看看 C# 中的 System.Reflection 範例 -

範例

using System;
using System.Reflection;

[AttributeUsage(AttributeTargets.All)]
public class HelpAttribute : System.Attribute {
   public readonly string Url;

   public string Topic // Topic is a named parameter {
      get {
         return topic;
      }

      set {
         topic = value;
      }
   }

   public HelpAttribute(string url) // url is a positional parameter {
      this.Url = url;
   }

   private string topic;
}

[HelpAttribute("Information on the class MyClass")]
class MyClass {
}

namespace AttributeAppl {
   class Program {
      static void Main(string[] args) {
         System.Reflection.MemberInfo info = typeof(MyClass);
         object[] attributes = info.GetCustomAttributes(true);
         for (int i = 0; i < attributes.Length; i++) {
            System.Console.WriteLine(attributes[i]);
         }
         Console.ReadKey();
      }
   }
}

以上是C# 中的 System.Reflection.Module 是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除