Last post Apr 28, 2016 05:18 PM by PatriceSc
Oct 25, 2009 07:08 PM|johnson1234|LINK
Hi, I was wondering if Reflection can be used for something like the following...
I am opening a table and reading through the "Name" column. The name column represents the name of a Global Variable inside my Shared_Routines module located in my App_Code folder of my ASP.NET web application.
Column: Name (name of the Global Variable)
Column: Value (value of the Global Variable)
|- Public Module Shared_Routines
|- Global Variables...
Public GlobalVar1 As Boolean = True
Public GlobalVar2 As String = "test"
Public GlobalVar3 As Long = 1234
Inside my Global.asax I connect to the database and iterate through a table containing a list of these three Global Variables (i.e. GlobalVar1, GlobalVar2, GlobalVar3) and want to dynamically store the
values of these Global Variables into the "Value" field of the same table.
I could use a SELECT CASE statement to obtain the values of the Global Variables by hard-coding all of the Global Variable names inside the SELECT CASE, but it would be simpler and more dynamic coding to use Reflection in some way to say...
DataSet("Value") = <some reflection to find the global variable with the same name as DataSet("Name")>
I have more than 3 Global Variables and I am not concerned if Reflection provides slower performance than a potentially gigantic SELECT CASE statement.
Apr 28, 2016 05:18 PM|PatriceSc|LINK
It should be possible. Try
https://msdn.microsoft.com/en-us/library/system.reflection.module(v=vs.110).aspx Which version do you use? You may have other possible approach. Also note that global variables are shared by ALL users. Is this what you want?
You may want to rather explain your final goal but you may have better options for doing that. My understanding for now would be that you try to expose to your app, application wide settings that are stored in the database. Is this your intent?