Calling a generic function in VB.NET / C#

Posted by Quandary on Stack Overflow See other posts from Stack Overflow or by Quandary
Published on 2010-06-02T12:30:04Z Indexed on 2010/06/02 12:33 UTC
Read the original article Hit count: 413

Filed under:
|
|
|
|

Question: I want to call a generic function, defined as:

      Public Shared Function DeserializeFromXML(Of T)(Optional ByRef strFileNameAndPath As String = Nothing) As T

Now when I call it, I wanted to do it with any of the variants below:

Dim x As New XMLserialization.cConfiguration
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of x)()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(GetType(x))()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of GetType(x))()

But it doesn't work. I find it very annoying and unreadable having to type

    x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of XMLserialization.cConfiguration)()

Is there a way to call a generic function by getting the type from the instance ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET