كيفية القيام بما يلي: الحصول على نوع و معلومات عضو من تجميع
مساحة الاسم System.Reflection تحتوي على العديد من الطرق للحصول على المعلومات من التجميع. يوضح هذا القسم إحدى هذه الطرق. للحصول على مزيد من المعلومات، راجع نظرة عامة على الانعكاس.
المثال التالي يحصل على نوع و معلومات عضو من تجميع.
مثال
Imports System
Imports System.Reflection
Class Asminfo1
Shared Sub Main()
Console.WriteLine("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(vbCrLf & "There are {0} documentable members in ", Mymemberinfoarray.Length)
Console.WriteLine("{0}.", MyType.FullName)
Dim Mymemberinfo As MemberInfo
For Each Mymemberinfo In Mymemberinfoarray
Console.WriteLine(Mymemberinfo.Name)
Next Mymemberinfo
End Sub
End Class
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);
}
}
}