G
Guest
I try to initialize some Public Variable in a class use for code-behind
The idea is to check all uxMsgXXX variables, declare in top of my class and
assign the string value from a DB request. Why do That ? Multilinguage
apps...
If I'm able to do so, I already have an interface to enter the translation
for each variables. Also, this way I don't need to deploy extra files for the
translation.
I can get all my fields from my class with System.Reflection.FieldInfo but
I'm not able to getvalue or setvalue. I can not find the good method/syntax
to do so.
Please help !!!
Ex.:
Public Class Extension
Inherits IcbWebform
public uxMsgError as string = "English Error Message"
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Dim oTrans As New Translation
InitializeComponent()
oTrans.LoadLngString(GetType(Extension))
End Sub
End class
So when Page_Init() is finish, uxMsgError = "Message d'erreur Francais"
oTrans.LoadLngString()
Public Sub LoadLngString(ByVal oPage As Type)
Dim fieldInfo() As System.Reflection.FieldInfo
Dim value As String
Dim o As Type
Dim i As Integer
o = oPage
fieldInfo = oPage.GetFields()
For i = 0 To fieldInfo.Length - 1
Dim fd As String = fieldInfo(i).Name
o.GetType().InvokeMember(fd, Reflection.BindingFlags.SetField,
Nothing, o, New Object() {"set string value"})
Dim rtStr As String = CType(o.GetType.InvokeMember(fd,
Reflection.BindingFlags.GetField, Nothing, o, Nothing), String)
Next
End Sub
The idea is to check all uxMsgXXX variables, declare in top of my class and
assign the string value from a DB request. Why do That ? Multilinguage
apps...
If I'm able to do so, I already have an interface to enter the translation
for each variables. Also, this way I don't need to deploy extra files for the
translation.
I can get all my fields from my class with System.Reflection.FieldInfo but
I'm not able to getvalue or setvalue. I can not find the good method/syntax
to do so.
Please help !!!
Ex.:
Public Class Extension
Inherits IcbWebform
public uxMsgError as string = "English Error Message"
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Dim oTrans As New Translation
InitializeComponent()
oTrans.LoadLngString(GetType(Extension))
End Sub
End class
So when Page_Init() is finish, uxMsgError = "Message d'erreur Francais"
oTrans.LoadLngString()
Public Sub LoadLngString(ByVal oPage As Type)
Dim fieldInfo() As System.Reflection.FieldInfo
Dim value As String
Dim o As Type
Dim i As Integer
o = oPage
fieldInfo = oPage.GetFields()
For i = 0 To fieldInfo.Length - 1
Dim fd As String = fieldInfo(i).Name
o.GetType().InvokeMember(fd, Reflection.BindingFlags.SetField,
Nothing, o, New Object() {"set string value"})
Dim rtStr As String = CType(o.GetType.InvokeMember(fd,
Reflection.BindingFlags.GetField, Nothing, o, Nothing), String)
Next
End Sub