Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic object propertys

Status
Not open for further replies.

N3XuS

Programmer
Mar 1, 2002
339
BE
I'm mega noob in ASP.net. What I'm trying to do is read an XML file and make an object of each record. Thus getting the propertys from the XML file and set them accordingly then put the objects back in an array. The prob here is how do I dynamically create the propertys from the data in the dataset... I can't know in advance what kind of object I'm gonna get.
 
Basically the code would look something like this... but I have no clue how to handle that object thing as argument ...
Code:
Imports System.Xml.Serialization
Imports System.Xml
Imports System.IO

Public Class clsXMLCommunicatorFunctions

    Public Function writeXML(ByVal strFilename As String, ByVal oObject As Object)
        Dim oXS As XmlSerializer = New XmlSerializer(GetType(oObject))
        Dim oStmW = New StreamWriter(strFilename)
        oXS.Serialize(oStmW, oObject)
        oStmW.Close()
    End Function

    Public Function getXML(ByVal strFilename As String, ByVal oObject As Object) As oNed
        Dim oXS As XmlSerializer = New XmlSerializer(GetType(oObject))
        Dim oNed As oObject
        Dim oStmR As StreamReader

        oStmR = New StreamReader(strFilename)
        oNed = oXS.Deserialize(oStmR)
        oStmR.Close()

    End Function

End Class

I can't return an object oNed, or do "Dim oNed As oObject"
it says oObject is not a type ... or do GetType(oObject)
the object resides in a whole differnt classlibrary and I have no knowledge what it'll be... it could be any object.

Many thanks in advance :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top