Share via


Comment : obtenir des informations relatives au type et aux membres à partir d'un assembly

Mise à jour : novembre 2007

L'espace de noms System.Reflection contient plusieurs méthodes pour obtenir des informations à partir d'un assembly. Cette section illustre l'une de ces méthodes. Pour plus d'informations, consultez Vue d'ensemble de la réflexion.

L'exemple suivant obtient des informations relatives au type et aux membres à partir d'un assembly.

Exemple

Imports System
Imports System.Reflection

Class Asminfo1
   
   'Entry point, which delegates to C-style main Private Function.
   Public Overloads Shared Sub Main()
      Main(System.Environment.GetCommandLineArgs())
   End Sub
   
   Overloads Public Shared Sub Main(args() As String)
      Console.WriteLine(ControlChars.Cr + "Reflection.MemberInfo")
      
      'Get the Type and MemberInfo. 
      'Insert the fully qualified class name inside the quotation marks in the following statement.
      Dim MyType As Type = Type.GetType("System.IO.BinaryReader")
      Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers((BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Static Or BindingFlags.Instance Or BindingFlags.DeclaredOnly))
      
      'Get and display the DeclaringType method. 
      Console.Write(ControlChars.Cr + "There are {0} documentable members in ", Mymemberinfoarray.Length)
      Console.Write("{0}.", MyType.FullName)
      
      Dim Mymemberinfo As MemberInfo
      For Each Mymemberinfo In  Mymemberinfoarray
         Console.Write((ControlChars.Cr + Mymemberinfo.Name))
      Next Mymemberinfo
   End Sub 'Main
End Class 'Asminfo1
using System;
using System.Reflection;
class Asminfo1
{ 
  public static void Main(string[] args)
   { 
   Console.WriteLine ("\nReflection.MemberInfo");

      //Get the Type and MemberInfo. 
      //Insert the fully qualified class name inside the quotation marks in the following statement.
      Type MyType =Type.GetType("System.IO.BinaryReader"); 
      MemberInfo[] Mymemberinfoarray = MyType.GetMembers(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance|BindingFlags.DeclaredOnly); 

      //Get and display the DeclaringType method. 
      Console.Write("\nThere are {0} documentable members in ", Mymemberinfoarray.Length);
      Console.Write("{0}.", MyType.FullName); 

      foreach (MemberInfo Mymemberinfo in Mymemberinfoarray) 
          { 
           Console.Write("\n" + Mymemberinfo.Name);
          }
   }
}

Voir aussi

Concepts

Programmation avec des domaines d'application

Vue d'ensemble de la réflexion

Autres ressources

Hébergement du Common Language Runtime

Utilisation des domaines d'application