I got that line of code and it’s getting duplicated a lot
myString = If(myObj1.myProp Is Nothing, "", If(want = "abr", myObj1.myProp.abr, myObj1.myProp.desc))
that line x n, just change “myObj1” to “anything” and “myProp” to “anything“
I tried this
Public Function getDesc(Of t)(ByVal obj As t) As String
Return If(obj Is Nothing, "", If(want = "abr", obj.abr, obj.Desc))
End Function
the problem here is t doesn’t know that it got abr / desc properties
Create a method, and pass in the variable parts as arguments.
Create the method as such, so that the method knows that T has those specific properties. Put a constraint on your generic type (define that T should inherit some kind of interface in which those properties are defined).
In C#, you can do it like this. (It can be done in VB.NET as well, but I don’t know the syntax).
The interface ‘ISomeInterface’ should then define the abr and Desc properties.
You will also have to make sure that the types you use in your method call, implement this interface, otherwise you’ll get a compile-error.
I believe that, in VB.NET, it would look something like ths: