Name of assembly from namespace string

Is there a way to get the assembly name from a namespace string? For example, get "mscorlib" from "System".

The reason for my question is that I create Boo scripts using the by-method, and I need to add namespaces programmatically. The resulting string in Boo will read:

import System from mscorlib 

I could obviously pass a collection of import strings, but if I could just pass a list of links, that would be much more scalable!

Many thanks

+4
source share
2 answers

Names and names of namespaces are completely orthogonal. There is no real relationship between them. Unless you examine a set of well-known assemblies to see which namespaces they contain, there is no real way to get the assembly name from the namespace name. For example, what would you do if two assemblies (like mscorlib and System.Core ) declared a type in the System namespace?

+5
source

You can get it from the type:

 Console.WriteLine(typeof(System.Object).Module.Name); 

In the namespace, remember that more than one assembly can define the same namespace.

0
source

Source: https://habr.com/ru/post/1300396/


All Articles