PrintPropertyDictionary Classe

Definição

Representa uma coleção de propriedades e valores associados a um objeto no namespace System.Printing.Represents a collection of properties and values that are associated with an object in the System.Printing namespace.

public ref class PrintPropertyDictionary : System::Collections::Hashtable, IDisposable
[System.Serializable]
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable
type PrintPropertyDictionary = class
    inherit Hashtable
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
Public Class PrintPropertyDictionary
Inherits Hashtable
Implements IDisposable
Herança
PrintPropertyDictionary
Atributos
Implementações

Exemplos

O exemplo a seguir mostra como usar essa classe para instalar uma segunda impressora que difere em suas propriedades de uma impressora existente somente no local, na porta e no status compartilhado.The following example shows how to use this class to install a second printer that differs in its properties from an existing printer only in location, port, and shared status.

LocalPrintServer myLocalPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties = sourcePrintQueue.PropertiesCollection;

// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared", true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);

// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +"\"");
myPrintProperties.SetProperty("ShareName", theShareName);

// Specify the physical location of the new printer using Remove/Add methods
PrintStringProperty theLocation = new PrintStringProperty("Location", "the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);

// Specify the port for the new printer
String[] port = new String[] { "COM1:" };

// Install the new printer on the local print server
PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue("My clone of " + sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties);
myLocalPrintServer.Commit();

// Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName);
Console.WriteLine("Press Return to continue ...");
Console.ReadLine();
Dim myLocalPrintServer As New LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer)
Dim sourcePrintQueue As PrintQueue = myLocalPrintServer.DefaultPrintQueue
Dim myPrintProperties As PrintPropertyDictionary = sourcePrintQueue.PropertiesCollection

' Share the new printer using Remove/Add methods
Dim [shared] As New PrintBooleanProperty("IsShared", True)
myPrintProperties.Remove("IsShared")
myPrintProperties.Add("IsShared", [shared])

' Give the new printer its share name using SetProperty method
Dim theShareName As New PrintStringProperty("ShareName", """Son of " & sourcePrintQueue.Name & """")
myPrintProperties.SetProperty("ShareName", theShareName)

' Specify the physical location of the new printer using Remove/Add methods
Dim theLocation As New PrintStringProperty("Location", "the supply room")
myPrintProperties.Remove("Location")
myPrintProperties.Add("Location", theLocation)

' Specify the port for the new printer
Dim port() As String = { "COM1:" }


' Install the new printer on the local print server
Dim clonedPrinter As PrintQueue = myLocalPrintServer.InstallPrintQueue("My clone of " & sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties)
myLocalPrintServer.Commit()

' Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName)
Console.WriteLine("Press Return to continue ...")
Console.ReadLine()

O exemplo a seguir mostra como usar essa classe para descobrir em tempo de execução as propriedades e os tipos dessas propriedades, de um objeto do sistema de impressão, sem usar reflexão.The following example shows how to use this class to discover at run time the properties, and the types of those properties, of a print system object, without using reflection.


// 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()

Comentários

A coleção assume a forma de um dicionário de Hashtable.The collection takes the form of a Hashtable dictionary. A propriedade Value de cada DictionaryEntry na coleção é uma instância de uma classe que é derivada de PrintProperty.The Value property of each DictionaryEntry in the collection is an instance of a class that is derived from PrintProperty.

Construtores

PrintPropertyDictionary()

Inicializa uma nova instância da classe PrintPropertyDictionary.Initializes a new instance of the PrintPropertyDictionary class.

PrintPropertyDictionary(SerializationInfo, StreamingContext)

Inicializa uma nova instância da classe PrintPropertyDictionary e a fornece com o SerializationInfo e o StreamingContext especificados.Initializes a new instance of the PrintPropertyDictionary class and provides it with the specified SerializationInfo and StreamingContext.

Propriedades

comparer

Obtém ou define o IComparer a ser usado para o Hashtable.Gets or sets the IComparer to use for the Hashtable.

(Herdado de Hashtable)
Count

Obtém o número de pares chave-valor contidos no Hashtable.Gets the number of key/value pairs contained in the Hashtable.

(Herdado de Hashtable)
EqualityComparer

Obtém o IEqualityComparer a ser usado para o Hashtable.Gets the IEqualityComparer to use for the Hashtable.

(Herdado de Hashtable)
hcp

Obtém ou define o objeto que pode dispensar códigos hash.Gets or sets the object that can dispense hash codes.

(Herdado de Hashtable)
IsFixedSize

Obtém um valor que indica se o Hashtable tem um tamanho fixo.Gets a value indicating whether the Hashtable has a fixed size.

(Herdado de Hashtable)
IsReadOnly

Obtém um valor que indica se o Hashtable é somente leitura.Gets a value indicating whether the Hashtable is read-only.

(Herdado de Hashtable)
IsSynchronized

Obtém um valor que indica se o acesso à Hashtable é sincronizado (thread-safe).Gets a value indicating whether access to the Hashtable is synchronized (thread safe).

(Herdado de Hashtable)
Item[Object]

Obtém ou define o valor associado à chave especificada.Gets or sets the value associated with the specified key.

(Herdado de Hashtable)
Keys

Obtém uma ICollection que contém as chaves na Hashtable.Gets an ICollection containing the keys in the Hashtable.

(Herdado de Hashtable)
SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso ao Hashtable.Gets an object that can be used to synchronize access to the Hashtable.

(Herdado de Hashtable)
Values

Obtém um ICollection que contém os valores no Hashtable.Gets an ICollection containing the values in the Hashtable.

(Herdado de Hashtable)

Métodos

Add(Object, Object)

Adiciona um elemento com a chave e o valor especificados ao Hashtable.Adds an element with the specified key and value into the Hashtable.

(Herdado de Hashtable)
Add(PrintProperty)

Adiciona o objeto especificado (de uma classe derivada de PrintProperty) no dicionário.Adds the specified object (of a class that is derived from PrintProperty) into the dictionary.

Clear()

Remove todos os elementos do Hashtable.Removes all elements from the Hashtable.

(Herdado de Hashtable)
Clone()

Cria uma cópia superficial do Hashtable.Creates a shallow copy of the Hashtable.

(Herdado de Hashtable)
Contains(Object)

Determina se a Hashtable contém uma chave específica.Determines whether the Hashtable contains a specific key.

(Herdado de Hashtable)
ContainsKey(Object)

Determina se a Hashtable contém uma chave específica.Determines whether the Hashtable contains a specific key.

(Herdado de Hashtable)
ContainsValue(Object)

Determina se o Hashtable contém um valor específico.Determines whether the Hashtable contains a specific value.

(Herdado de Hashtable)
CopyTo(Array, Int32)

Copia os elementos Hashtable para uma instância Array unidimensional no índice especificado.Copies the Hashtable elements to a one-dimensional Array instance at the specified index.

(Herdado de Hashtable)
Dispose()

Libera todos os recursos que estão sendo usados pelo PrintPropertyDictionary.Releases all the resources that are being used by the PrintPropertyDictionary.

Dispose(Boolean)

Libera os recursos não gerenciados que estão sendo usados pelo PrintPropertyDictionary e libera opcionalmente os recursos gerenciados.Releases the unmanaged resources that are being used by the PrintPropertyDictionary and optionally releases the managed resources.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetEnumerator()

Retorna um IDictionaryEnumerator que itera pelo Hashtable.Returns an IDictionaryEnumerator that iterates through the Hashtable.

(Herdado de Hashtable)
GetHash(Object)

Retorna o código hash da chave especificada.Returns the hash code for the specified key.

(Herdado de Hashtable)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Preenche um SerializationInfo com os dados necessários para serializar o PrintPropertyDictionary.Populates a SerializationInfo with the data that is needed to serialize the PrintPropertyDictionary.

GetProperty(String)

Obtém o objeto (de uma classe derivada de PrintProperty) que representa a propriedade especificada.Gets the object (of a class that is derived from PrintProperty) that represents the specified property.

GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
KeyEquals(Object, Object)

Compara um Object específico com uma chave específica no Hashtable.Compares a specific Object with a specific key in the Hashtable.

(Herdado de Hashtable)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
OnDeserialization(Object)

Implementa a interface ISerializable e gera o evento de desserialização quando a desserialização for concluída.Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(Object)

Remove o elemento com a chave especificada do Hashtable.Removes the element with the specified key from the Hashtable.

(Herdado de Hashtable)
SetProperty(String, PrintProperty)

Define o valor do atributo especificado como um objeto de uma classe derivada de PrintProperty.Sets the value of the specified attribute to an object of a class that is derived from PrintProperty.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Implantações explícitas de interface

IEnumerable.GetEnumerator()

Retorna um enumerador que itera em uma coleção.Returns an enumerator that iterates through a collection.

(Herdado de Hashtable)

Métodos de Extensão

Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.Enables parallelization of a query.

AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable.

Aplica-se a