views:

46

answers:

2

I have a shared Queue that I use to dump various messages contained in different Classes, so I have its type as Object.

The prob is, the messages are dequeued and processed but since the message type vary, Intellisense doesn't show the classes properties or methods.

How does one find get Intellisense to work to?

+1  A: 

You will need to provide a common base class or interface that these various message classes share. So instead of a queue of Objects, you would instead have a queue of MessageBase or IMessage. The methods and properties you wish to access would need to be defined within the base/interface. Intellisense would then show those properties and methods (but not the additional properties/methods you define within each class).

Anthony Pegram
A: 

There are two Queue classes in the .NET Framework, the difference is they were released at different times - one is newer. Use the strongly typed Queue(Of T) shown in the second list item below to achieve Intellisense and to have a strongly typed instance you can program against easily...

Code sample

Dim numbers As New Queue(Of String)

The two Queue classes:

  1. System.Collections.Queue

    • Intellisense shows an Object (Likely this is your problem).
    • from .NET 1.0
    • results in weakly typed Object elements
  2. System.Collections.Generic.Queue(Of T)

    • Intellisense will show the strongly type T members (Use this instead)
    • from .NET 2.0
    • results in strongly typed (Of T) elements where you specify T

Use the links to visit the documentation, put the doc page in VB syntax mode, and scroll down to the Examples section to see its usage.


Other

If you're using a Queue different from the ones mentioned above, you can always Convert/cast the dequeued objects back into their strongly-typed values using mechanisms like the following:

John K
Thanks for the help John.
Alex