Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can I determine the type of a single object whose collection is given?

How can I determine the type of a single object whose collection is given?

Scheduled Pinned Locked Moved Visual Basic
questionhelpdiscussion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vidvan
    wrote on last edited by
    #1

    Hi, I need to write a generic function which, a) accepts a collection object b) determines the type of a single object (i.e. collection of what type) c) instantiate an object of the type found in step b (using reflection maybe) Here is the function declaration, Function GetNewSingleObject(ByVal colObjectCollection as Collection) As Object My question is how do I determine the type of a single object (step b). Any thoughts? Appreciate your help. Thanks. Vidvan

    J A 2 Replies Last reply
    0
    • V Vidvan

      Hi, I need to write a generic function which, a) accepts a collection object b) determines the type of a single object (i.e. collection of what type) c) instantiate an object of the type found in step b (using reflection maybe) Here is the function declaration, Function GetNewSingleObject(ByVal colObjectCollection as Collection) As Object My question is how do I determine the type of a single object (step b). Any thoughts? Appreciate your help. Thanks. Vidvan

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      Is it to be assumed that every member of the collection is of the same type? The supplied framework collections objects make no such assumption. If so, check the first member and use the GetType()[^] method derived from the object base class. From there you can use reflection to instanciate a new object.

      α.γεεκ

      Fortune passes everywhere.
      Duke Leto Atreides

      1 Reply Last reply
      0
      • V Vidvan

        Hi, I need to write a generic function which, a) accepts a collection object b) determines the type of a single object (i.e. collection of what type) c) instantiate an object of the type found in step b (using reflection maybe) Here is the function declaration, Function GetNewSingleObject(ByVal colObjectCollection as Collection) As Object My question is how do I determine the type of a single object (step b). Any thoughts? Appreciate your help. Thanks. Vidvan

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        use the function TypeName

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups