Gewusst wie: Abrufen von Typ- und Memberinformationen aus einer Assembly
Der System.Reflection-Namespace enthält viele Methoden, mit denen Sie Informationen aus einer Assembly erhalten können. In diesem Abschnitt wird eine dieser Methoden vorgestellt. Zusätzliche Informationen finden Sie unter Übersicht über Reflektion.
Mit dem folgenden Beispielcode werden Typ- und Memberinformationen aus einer Assembly abgerufen.
Beispiel
Imports System
Imports System.Reflection
Class Asminfo1
Public Shared Sub Main()
Console.WriteLine ("\nReflection.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("\nThere are {0} documentable members in ", Mymemberinfoarray.Length)
Console.Write("{0}.", MyType.FullName)
For Each Mymemberinfo As MemberInfo in Mymemberinfoarray
Console.Write("\n" + Mymemberinfo.Name)
Next
End Sub
End Class
using System;
using System.Reflection;
class Asminfo1
{
public static void Main()
{
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);
}
}
}
using namespace System;
using namespace System::Reflection;
ref class Asminfo1
{
public:
static void Main()
{
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");
array<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);
for each (MemberInfo^ Mymemberinfo in Mymemberinfoarray)
{
Console::Write("\n" + Mymemberinfo->Name);
}
}
};
int main()
{
Asminfo1::Main();
}
Siehe auch
Konzepte
Programmieren mit Anwendungsdomänen