How can I determine the type of a single object whose collection is given?
-
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
-
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
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 -
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