To resolve a namespace conflict between assemblies in C#, I gave one an Alias of NLog
:
Now, I can refer to a namespace within that assembly like so:
public class Logger : NLog::NLog.LogReceiverService
{
// ...
}
However, this won't compile until I use the extern alias
keyword at the top of my file:
extern alias NLog;
My Question:
What purpose does the extern alias
keyword serve? Shouldn't NLog::NLog.LogReceiverService
be sufficient to fully disambiguate the assembly alias, namespace and type I'm referring to?
extern alias GridV2; Each extern alias declaration introduces an additional root-level namespace that parallels (but does not lie within) the global namespace. Thus types from each assembly can be referred to without ambiguity by using their fully qualified name, rooted in the appropriate namespace-alias.
An extern alias allows you to bring in the code in a DLL under a separate “root” namespace, parallel to the global namespace, with a different name of your own choosing. You must do two things to use an extern alias. First, apply a namespace alias to the DLL that you're referencing.
Question 3: Which of the following keyword is used to reference two assemblies with the same fully qualified type names? This creates the external aliases GridV1 and GridV2 . To use these aliases from within a program, reference them by using the extern keyword.
Setting the Aliases property on the reference will only designate it as that alias while the initial load of assembly references is done for your project as run time. In order to use that aliased assembly reference in your file, you must specify that you are going to use it via the extern alias keyword, which sets the compiler directives to look for that alias.
You would think that they would have some type of global aliasing, but I am thinking they force the explicit alias use due to a performance hit that is incurred on the alias.
Here is the reference material on extern alias: http://msdn.microsoft.com/en-us/library/ms173212.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With