How to: Get Print System Object Properties Without Reflection

Using reflection to itemize the properties (and the types of those properties) on an object can slow application performance. The System.Printing.IndexedProperties namespace provides a means to getting this information with using reflection.

The steps for doing this are as follows.

  1. Create an instance of the type. In the example below, the type is the PrintQueue type that ships with Microsoft .NET Framework, but nearly identical code should work for types that you derive from PrintSystemObject.

  2. Create a PrintPropertyDictionary from the type's PropertiesCollection. The Value property of each entry in this dictionary is an object of one of the types derived from PrintProperty.

  3. Enumerate the members of the dictionary. For each of them, do the following.

  4. Up-cast the value of each entry to PrintProperty and use it to create a PrintProperty object.

  5. Get the type of the Value of each of the PrintProperty object.


            // 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();
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft