Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
A reflektáció használata az objektumok tulajdonságainak (és azok típusainak) felsorolására lelassíthatja az alkalmazás teljesítményét. A System.Printing.IndexedProperties névtér lehetővé teszi az információk tükröződés nélküli lekérését.
példa
Ennek lépései a következők.
Hozzon létre egy ilyen típusú példányt. Az alábbi példában a típus a Microsoft .NET-keretrendszerrel rendelkező PrintQueue típus, de a PrintSystemObjectszármazó típusok esetében majdnem azonos kódnak kell működnie.
Hozzon létre egy PrintPropertyDictionary a(z) PropertiesCollectiontípusból. A szótár minden bejegyzésének Value tulajdonsága egy olyan objektum, amely a PrintProperty-ből származó valamelyik típushoz tartozik.
Sorolja fel a szótár tagjait. Mindegyiknél tegye a következőket.
Emelje az egyes bejegyzések értékét a PrintProperty-ra, és használja egy PrintProperty objektum létrehozására.
Az egyes Value objektumok PrintProperty típusának lekérése.
// Enumerate the properties, and their types, of a queue without using Reflection
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
PrintPropertyDictionary printQueueProperties = defaultPrintQueue.PropertiesCollection;
Console.WriteLine("These are the properties, and their types, of {0}, a {1}", defaultPrintQueue.Name, defaultPrintQueue.GetType().ToString() +"\n");
foreach (DictionaryEntry entry in printQueueProperties)
{
PrintProperty property = (PrintProperty)entry.Value;
if (property.Value != null)
{
Console.WriteLine(property.Name + "\t(Type: {0})", property.Value.GetType().ToString());
}
}
Console.WriteLine("\n\nPress Return to continue...");
Console.ReadLine();
' Enumerate the properties, and their types, of a queue without using Reflection
Dim localPrintServer As New LocalPrintServer()
Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()
Dim printQueueProperties As PrintPropertyDictionary = defaultPrintQueue.PropertiesCollection
Console.WriteLine("These are the properties, and their types, of {0}, a {1}", defaultPrintQueue.Name, defaultPrintQueue.GetType().ToString() + vbLf)
For Each entry As DictionaryEntry In printQueueProperties
Dim [property] As PrintProperty = CType(entry.Value, PrintProperty)
If [property].Value IsNot Nothing Then
Console.WriteLine([property].Name & vbTab & "(Type: {0})", [property].Value.GetType().ToString())
End If
Next entry
Console.WriteLine(vbLf & vbLf & "Press Return to continue...")
Console.ReadLine()
Lásd még
.NET Desktop feedback