PrintPropertyDictionary 类

定义

表示与 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
继承
PrintPropertyDictionary
属性
实现

示例

下面的示例演示如何使用此类在其属性中安装仅在位置、端口和共享状态中不同于现有打印机的第二台打印机。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()

下面的示例演示如何使用此类在运行时发现打印系统对象的属性和这些属性的类型,而无需使用反射。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()

注解

集合采用Hashtable字典的形式。The collection takes the form of a Hashtable dictionary. 集合中每个DictionaryEntryPrintProperty属性都是派生自的类的实例。ValueThe Value property of each DictionaryEntry in the collection is an instance of a class that is derived from PrintProperty.

构造函数

PrintPropertyDictionary()

初始化 PrintPropertyDictionary 类的新实例。Initializes a new instance of the PrintPropertyDictionary class.

PrintPropertyDictionary(SerializationInfo, StreamingContext)

初始化 PrintPropertyDictionary 类的一个新实例,并为其提供指定的 SerializationInfoStreamingContextInitializes a new instance of the PrintPropertyDictionary class and provides it with the specified SerializationInfo and StreamingContext.

属性

comparer

获取或设置要用于 IComparerHashtableGets or sets the IComparer to use for the Hashtable.

(继承自 Hashtable)
Count

获取包含在 Hashtable 中的键/值对的数目。Gets the number of key/value pairs contained in the Hashtable.

(继承自 Hashtable)
EqualityComparer

获取要用于 IEqualityComparerHashtableGets the IEqualityComparer to use for the Hashtable.

(继承自 Hashtable)
hcp

获取或设置可分配哈希代码的对象。Gets or sets the object that can dispense hash codes.

(继承自 Hashtable)
IsFixedSize

获取一个值,该值指示 Hashtable 是否具有固定大小。Gets a value indicating whether the Hashtable has a fixed size.

(继承自 Hashtable)
IsReadOnly

获取一个值,该值指示 Hashtable 是否为只读。Gets a value indicating whether the Hashtable is read-only.

(继承自 Hashtable)
IsSynchronized

获取一个值,该值指示是否同步对 Hashtable 的访问(线程安全)。Gets a value indicating whether access to the Hashtable is synchronized (thread safe).

(继承自 Hashtable)
Item[Object]

获取或设置与指定的键关联的值。Gets or sets the value associated with the specified key.

(继承自 Hashtable)
Keys

获取包含 ICollection 中的键的 HashtableGets an ICollection containing the keys in the Hashtable.

(继承自 Hashtable)
SyncRoot

获取可用于同步对 Hashtable 的访问的对象。Gets an object that can be used to synchronize access to the Hashtable.

(继承自 Hashtable)
Values

获取一个 ICollection,它包含 Hashtable 中的值。Gets an ICollection containing the values in the Hashtable.

(继承自 Hashtable)

方法

Add(Object, Object)

将带有指定键和值的元素添加到 Hashtable 中。Adds an element with the specified key and value into the Hashtable.

(继承自 Hashtable)
Add(PrintProperty)

将指定的对象(属于从 PrintProperty 派生的类)添加到该目录中。Adds the specified object (of a class that is derived from PrintProperty) into the dictionary.

Clear()

Hashtable 中移除所有元素。Removes all elements from the Hashtable.

(继承自 Hashtable)
Clone()

创建 Hashtable 的浅表副本。Creates a shallow copy of the Hashtable.

(继承自 Hashtable)
Contains(Object)

确定 Hashtable 是否包含特定键。Determines whether the Hashtable contains a specific key.

(继承自 Hashtable)
ContainsKey(Object)

确定 Hashtable 是否包含特定键。Determines whether the Hashtable contains a specific key.

(继承自 Hashtable)
ContainsValue(Object)

确定 Hashtable 是否包含特定值。Determines whether the Hashtable contains a specific value.

(继承自 Hashtable)
CopyTo(Array, Int32)

Hashtable 元素复制到一维 Array 实例中的指定索引位置。Copies the Hashtable elements to a one-dimensional Array instance at the specified index.

(继承自 Hashtable)
Dispose()

释放正在由 PrintPropertyDictionary 使用的所有资源。Releases all the resources that are being used by the PrintPropertyDictionary.

Dispose(Boolean)

释放正在由 PrintPropertyDictionary 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources that are being used by the PrintPropertyDictionary and optionally releases the managed resources.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回循环访问 IDictionaryEnumeratorHashtableReturns an IDictionaryEnumerator that iterates through the Hashtable.

(继承自 Hashtable)
GetHash(Object)

返回指定键的哈希代码。Returns the hash code for the specified key.

(继承自 Hashtable)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

用序列化 SerializationInfo 所需的数据来填充 PrintPropertyDictionaryPopulates a SerializationInfo with the data that is needed to serialize the PrintPropertyDictionary.

GetProperty(String)

获取表示特定属性的对象(属于从 PrintProperty 派生的类)。Gets the object (of a class that is derived from PrintProperty) that represents the specified property.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
KeyEquals(Object, Object)

将特定 ObjectHashtable 中的特定键进行比较。Compares a specific Object with a specific key in the Hashtable.

(继承自 Hashtable)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(Object)

Hashtable 中移除包含指定键的元素。Removes the element with the specified key from the Hashtable.

(继承自 Hashtable)
SetProperty(String, PrintProperty)

设置对象的指定特性的值,该对象属于从 PrintProperty 派生的类。Sets the value of the specified attribute to an object of a class that is derived from PrintProperty.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(继承自 Hashtable)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于