How can i pass a non specific class to sub

时间:2018-06-04 17:37:34

标签: vb.net

I have code which takes a Soap Response and serializes into a xml so i can write it to console. Code works great but as i am trying to clean up my code i am trying to stick the code into a sub so i can use it for different responses.

Dim Response As ATTSoapReference.ATT_ADDR_VAL_RESP = newRequest.submitAddVal(ATT_ADDR)

    Dim serxml = New System.Xml.Serialization.XmlSerializer(Response.GetType())
    Dim ms = New MemoryStream()
    serxml.Serialize(ms, Response)
    Dim xml As String = Encoding.UTF8.GetString(ms.ToArray())
    Console.WriteLine(xml)

If i want to do it as a sub for only this request type i can use

Private Sub DebugXML(byval myResponse As ATTSoapReference.ATT_ADDR_VAL_RESP)
    Dim serxml = New System.Xml.Serialization.XmlSerializer(myResponse.GetType())
    Dim ms = New MemoryStream()
    serxml.Serialize(ms, myResponse)
    Dim xml As String = Encoding.UTF8.GetString(ms.ToArray())
    Console.WriteLine(xml)
End Sub

But i am looking for something that will allow me to pass any Soap Data Class to it instead of ATTSoapReference.ATT_ADDR_VAL_RESP

1 个答案:

答案 0 :(得分:0)

尝试如下所述,看看它是否有效。

Private Sub DebugXML(byval myResponse As Object)

     'May be you require casting, for some specific things.

End Sub
相关问题