vanderghast said:
I may be wrong, but I think that a namespace through a using will be
effectively 'loaded' ONLY if your code ever access it. So, if your code
use compiler directives ( #if / #endif ) such that a namespace is
never effectively referenced by your code, there is few to no penalty by
keeping the initial using refereeing to an un-used namespace (unless
doing so you got collisions/ambiguities in your way).
Minor nit:
Namespaces aren't referenced, assemblies are. You can have one assembly
define types from multiple namespaces, and you can have types from a
single namespace implemented in multiple assemblies.
But yes, you can reference an assembly in another assembly, and as long
as there's not actually any code _present_ in that assembly that calls
into the other assembly, you can successfully use the other assembly
without the first. Note that it's whether the code is _present_ or not
that's important; simply avoiding executing the code isn't sufficient.
It has to not be there at all.
Note that the "using" directive has nothing to do with this at all. It
doesn't count as "code" for the purposes of the requirement of an
assembly being present; you can have a "using" directive for a namespace
in the assembly, but as long as you don't actually have any executable
code using the assembly, it's still fine for it to not be there. On the
other hand, if you do have code using the assembly, eliminating the
"using" statement is not sufficient to eliminate the dependency on the
assembly.
The important thing to keep in mind here is that whether an assembly
needs to be present or not is entirely determined at compile time,
unless you use some kind of dynamic loading technique (e.g. reflection,
as I suggested in my other reply). And of course, at compile time you
don't know what version of the OS the application is actually executing
on, or what other libraries may be present (*), unless you actually
build specific versions of the code intended to be run on only specific
versions of the OS or with specific libraries present.
Pete
(*) (not counting dynamically generated and compiled code, of
course...there was no mention of that in the original question, and it's
rare enough we should be able to assume it's not a consideration here)