Computer >> Máy Tính >  >> Lập trình >> C#

System.Reflection.Module trong C # là gì?


Không gian tên System.Reflection chứa các lớp cho phép bạn lấy thông tin về ứng dụng và thêm động các kiểu, giá trị và đối tượng vào ứng dụng.

Nó có một phương thức khởi tạo mô-đun khởi tạo một phiên bản mới của lớp Mô-đun. Mô-đun là một tệp thực thi di động có một hoặc nhiều lớp và giao diện.

Hãy để chúng tôi xem một ví dụ về System.Reflection trong C # -

Ví dụ

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();
      }
   }
}