What is the System.Reflection.Module in C#?


The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.

It has a module constructor that initializes a new instance of the Module class. A module is a portable executable file that has one or more classes and interfaces.

Let us see an example of System.Reflection in C# −

Example

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

Updated on: 21-Jun-2020

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements