|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sub(Thing as Object) {thing = new Thing.GetType} ?Sorry for polluting the VB newsgroup with curly brackets, but I couldn't= = think how to get that question onto one line otherwise. Anyway, I'm trying to write a Sub, or Function which takes an object as = an = input and then creates a new object of the same type using that class' = constructor. VB isn't currently liking any of my attempts, but the general idea is to= = have: Private Function NewInterfaceObjectArray(ByVal InterfaceObject As = Object(), ByVal defaultValue As Integer) As InterfaceObjectClass() InterfaceObject =3D New InterfaceObject.GetType Return InterfaceObject End Function That's a bit messy, even for pseudocode, but I think you'll get the idea= .. I guess this is a bit of a weird question, but it's mostly because the = idea intrigued me while I was writing a long constructor for an object = made of object arrays, which were all interfaces onto a single object = type. I'm *sure* there was a good reason for coding that at the time... Anyway, I can get round the problem, but I'm interested in whether the = language supports the idea of the function I'm asking about, and the = question seems to be too obscure for google (or my use of google) to cop= e = with. KF = -- = Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ "Kristian Frost" <kfr***@gmail.com> schrieb: Obtain the type of the object passed to the method by calling its 'GetType' >Sorry for polluting the VB newsgroup with curly brackets, but I couldn't >think how to get that question onto one line otherwise. >Anyway, I'm trying to write a Sub, or Function which takes an object as an >input and then creates a new object of the same type using that class' >constructor. method. Then pass the type to 'Activator.CreateInstance' to create an instance of the type. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Database Connectivity
Querying a database using vb Foreign letters in text file insert key state Error "Unable to cast object of type"-- but types are the same! Deriving Combobox items indexes bypass security in Outlook Resolving Type mismatch, HOW How to keep statusStrip at the bottom of the ToolStripContainer GPS and VB .net 2005 |
|||||||||||||||||||||||