o will always come from an entiryRef/TEntity (from linq 2 sql)
I'm ok with a c# or vb.net solution (I will convert it into vb.net if you can't)
Public Function desc(Of t)(ByRef o As t, Optional ByVal PropPrefix As String = "desc") As String
If o Is Nothing Then
Return ""
Else
Dim bind = Reflection.BindingFlags.Public Or Reflection.BindingFlags.IgnoreCase Or Reflection.BindingFlags.Instance
Dim _desc = PropPrefix & If(var.Sess.lang = Sess.elang.en, PropPrefix & "en", "fr")
Dim pinfo As Reflection.PropertyInfo = o.GetType.GetProperty(_desc, bind)
Return pinfo.GetValue(o, Nothing).ToString
End If
End Function
little background
I have a database like this
tableUser
-----------------
id
name
countryid
tableCountry
--------
countryid
descEn
descFr
when I'm showing the information about a user, I want to easily show the good language selected in the application
that one example, I have lots more table and lot more lookup table
with linq 2 sql if the field in the database is null, the object will be "nothing"(null) and I'm catching that with the first if then I'm getting the corresponding language field