Ø总是来自一个entiryRef/TEntity(从LINQ 2 SQL)我目前正在使用反射来做到这一点,有没有更好的方法?
我确定与C#或vb.net解决方案(我会转换成vb.net如果你不能)
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
一点背景
我有这样
tableUser
-----------------
id
name
countryid
tableCountry
--------
countryid
descEn
descFr
数据库时,我展示关于用户的信息,我想轻松展现在应用程序中选择好语言
一个例子,我有很多更多的表,更多的查找表
与LINQ 2 SQL如果字段中数据库为空,对象将是“无”(null
)和我赶上与第一如果然后我得到了相应的语言领域
你到底在做什么? – 2009-09-23 17:33:03
看起来他根据配置的语言调用带“en”或“fr”前缀的方法。 – 2009-09-23 17:36:25
它会返回法语(descfr字段)和英语(descen字段) – Fredou 2009-09-23 17:36:26