开发者

Assembly name from namespace string

开发者 https://www.devze.com 2022-12-19 01:01 出处:网络
Is there a way of getting the assembly name from a namespace string?Eg, get \"mscorlib\" from \"System\".

Is there a way of getting the assembly name from a namespace string? Eg, get "mscorlib" from "System".

The reason for my question is I'm creating Boo scripts method-by-method and am required to add namespaces programmatically. The resulting string in Boo would read:

import System from mscorlib

I could obvi开发者_开发知识库ously pass in a collection of import strings, but if I can just pass a list of references, that would be far more scalable!

Many thanks


Assembly names and namespace names are totally orthogonal concepts. There are no real relations between them. Short of examining a set of known assemblies to see what namespaces they contain, there's no real way to get assembly name from namespace name. For instance, what would you do if two assemblies (both mscorlib and System.Core) declared a type in the System namespace?


You can get it from a type:

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

About the namespace, remember that more than one assembly could define the same namespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消