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
Unfortunately, runtime reflection will be required unless you can integrate a
descmethod into each object, perhaps through some sort of entity base class or code generation and partial classes.The code generation approach: For each entity class, if it contains one or more
descFooproperties, generate adescproperty that pulls the correct one. If you cannot modify the CodeDom before it is written, you can also compile the entity classes, reflect/introspect the results, generate partial classes, and recompile with the added code.Since these are entity classes, though, it appears to me as though a schema change might be preferable. Rather than using multiple
descFoocolumns, add a table consisting of {entity PK, language, text}.