tags:

views:

483

answers:

4

I'd like to map a reference to an object instead of the object value with an HashTable

configMapping.Add("HEADERS_PATH", Me.headers_path)

that way when I'm going to retrieve the value of "HEADERS_PATH" I'll be able to assign a value to Me.headers_path

something like the " & " operator in C

+1  A: 

make headers_path be a propriety (with set)

Enreeco
+3  A: 

I am assuming that *Me.headers_path* is a System.String. Because System.String are immutable what you want cannot be achieved. But you can add an extra level of indirection to achieve a similar behavior.

All problems in computer science can be solved by another level of indirection. Butler Lampson

Sample in C# (Please be kind to edit to VB and remove this comment later):

public class Holder<T> {
    public T Value { get; set; }
}

...

Holder<String> headerPath = new Holder<String>() { Value = "this is a test" };
configMapping.Add("HEADERS_PATH", headerPath);

...

((Holder<String>)configMapping["HEADERS_PATH"]).Value = "this is a new test";

// headerPath.Value == "this is a new test"
smink
+1  A: 

This would appear to be a dictionary, which in .Net 2.0 you could define as Dictionary if the references you want to update are always strings, or Dictionary (not recommended) if you want to get an arbitrary reference.

If you need to replace the values in the dictionary you could define your own class and provide some helper methods to make this easier.

marcj
+1  A: 

I am not entirely sure what you want to do. Assuming that smink is correct then here is the VB translation of his code. Sorry I can't edit it, I don't think I have enough rep yet.

public class Holder(Of T)
    public Value as T 
end class
...
Dim headerPath as new Holder(Of String)
headerPath.Value = "this is a test"
configMapping.Add("HEADERS_PATH", headerPath)
...
Directcast(configMapping["HEADERS_PATH"]),Holder(Of String)).Value = "this is a new test"

'headerPath.Value now equals "this is a new test"

@marcj - you need to escape the angled brackets in your answer, so use &lt; for a < and &gt; for a >. Again sorry I couldn't just edit your post for you.

pipTheGeek