Originally posted by: Markbnj
I'm not sure exactly what you mean by "One of the fields contains the name of a variable."
Are you saying that you have an XML element and want to get to the value? You can use the DOM to parse an XML file and load the values into objects that can be referenced at runtime.
But I suspect that is not what you're talking about.
Originally posted by: KB
You could use a HashTable and store the variable name as the key.
Dim hs As New Hashtable
hs.Add("total", 22)
If hs.Contains("total") Then
Dim variable As Object = hs.Item("total")
End If
'variable = 22
HashTable hs = new HashTable();
hs.Add("total", 22)
if(hs.Contains("total")) {
Object variable = hs.Item("total");
}
//variable = 22
Looks good to me. Reflection only works if there actually is that variable with that name defined on a real object somewhere. You can't just make stuff up (at least not without bytecode engineering...)Originally posted by: Apathetic
Originally posted by: KB
You could use a HashTable and store the variable name as the key.
Dim hs As New Hashtable
hs.Add("total", 22)
If hs.Contains("total") Then
Dim variable As Object = hs.Item("total")
End If
'variable = 22
HashTable hs = new HashTable();
hs.Add("total", 22)
if(hs.Contains("total")) {
Object variable = hs.Item("total");
}
//variable = 22
Dang it... You beat me to it...
Dave
Originally posted by: kamper
Looks good to me. Reflection only works if there actually is that variable with that name defined on a real object somewhere. You can't just make stuff up (at least not without bytecode engineering...)Originally posted by: Apathetic
Originally posted by: KB
You could use a HashTable and store the variable name as the key.
Dim hs As New Hashtable
hs.Add("total", 22)
If hs.Contains("total") Then
Dim variable As Object = hs.Item("total")
End If
'variable = 22
HashTable hs = new HashTable();
hs.Add("total", 22)
if(hs.Contains("total")) {
Object variable = hs.Item("total");
}
//variable = 22
Dang it... You beat me to it...
Dave
I'll bet that boils down to automated bytecode engineering (and as such, wouldn't really belong in a reflection class. 'Reflection' by definition is viewing, not modifying). But I have to admit, I'm not a .net programmer...Originally posted by: UCJefe
Not entirely true. Reflection.Emit namespace can be used to dynamically create variables, methods, aseemblies, etc.