jeudi 20 avril 2017

Calling a generic method with a class constrain in vb.net

Im trying to get the name of a variable in runtime using reflection, i read a lot and find in other question a code in c# for that, now in vb.net the code looks like this

Public Shared Function GetParameterName(Of T As Class)(item As T) As String
    If item Is Nothing Then
        Return String.Empty
    End If

    Return GetType(T).GetProperties()(0).Name
End Function

the problems is when i try to call the function in c# i would be like this where test is the variable

GetParameterName(new {test});

but in Visual im cant call like that and if try like this

GetParameterName({test})

or

GetParameterName(New Object() {test})

the generic method doesn't recognize the variable the properties like name just say "Length" and the value "1"

maybe is a simple thing but i really appreciate your help

Regards





Aucun commentaire:

Enregistrer un commentaire