Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Usar a reflexão para itemizar as propriedades (e os tipos dessas propriedades) em um objeto pode diminuir o desempenho do aplicativo. O namespace System.Printing.IndexedProperties fornece um meio para obter essas informações sem usar reflexão.
Exemplo
As etapas para fazer isso são as seguintes.
Crie uma instância do tipo. No exemplo abaixo, o tipo é o tipo PrintQueue que vem com o Microsoft .NET Framework, mas o código deve funcionar de forma quase idêntica para tipos que você deriva de PrintSystemObject.
Crie um PrintPropertyDictionary com base no PropertiesCollectiondo tipo. A propriedade Value de cada entrada neste dicionário é um objeto de um dos tipos derivados de PrintProperty.
Enumerar os membros do dicionário. Para cada um deles, faça o seguinte.
Converta o valor de cada entrada para PrintProperty e use-o para criar um objeto PrintProperty.
Obtenha o tipo da Value de cada objeto PrintProperty.
// 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()
Consulte também
- PrintProperty
- PrintSystemObject
- System.Printing.IndexedProperties
- PrintPropertyDictionary
- LocalPrintServer
- PrintQueue
- DictionaryEntry
- documentos no WPF
- Visão geral da impressão
.NET Desktop feedback