tags:

views:

103

answers:

4

I have some values (basically constants) defined in assembly (class library) A. I would like to use these settings in assembly B. Is there a way to do this other than having the assembly A have some sort of wrapper classes around these settings or not ?

A: 

I think you just can put the values in static class in Assembly A so you can access them from Assembly B.

Wael Dalloul
I was wondering whether there is a way that doesn't require the creation of a wrapper class.
Tomas Pajonk
A: 

If the settings are read from the config file then I think you must copy them into your applications config file.

Apart from that you can just reference the static settings class from your assembly. It should be in the default namespace you have selected.

Rune Grimstad
A: 

Remember, when you compile an assembly the compiler basically does a find and replace for constants. What this means is that if assembly A has a constant of say "Foo" and assembly B references that constant, when assembly B is compiled, that string "Foo" will be compiled into assembly B. So, if the constant in assembly A gets updated to "Bar", these changes will not be reflected in assembly B unless its recompiled.

Charlie
This applies for field members declared with the 'const' keyword, but not for `static readonly` members. Also, the OP mentioned "basically constants" as a concept, so they could even be get-only properties once you put them in code.
280Z28
Yeah you're right, I thought he meant he wanted to reference constants from another assembly
Charlie
I want these settings to be settable in the configuration of assembly A. As 280Z28 commented correcty I meant constant as a concept not literally. I wouldn't have a problem otherwise.
Tomas Pajonk
A: 

What about using AppDomain.CurrentDomain.SetData and GetData?

then when your app fires some event in the controlling assembly like Close() you synchronize the data to your assembly's Settings.

CynisterSix
I am not quite sure I can imagine how would that work. Why would I need to fire an event to read a set value ?
Tomas Pajonk