Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

c# - How to get Namespace of an Assembly?

Consider i have an assembly(class library dll) which i have loaded using the following code,

Assembly a = Assembly.LoadFrom(@"C:Documents and SettingsE454935My DocumentsVisual Studio 2005Projects
unit_dll_huttfor_hutt_projinDebugasdf.dll");   

and i need to get the type of the Assembly. In order to get the type i need the namespace of the assembly.

Type t = asm.GetType("NAMESPACE.CLASSNAME",false,true);             

how can i get the Namespace in the above line.?! as inorder to get the Namespace, i need to get the type..?

Type.Namespace;

i.e i need to get the Namespace of the assembly which can be used to get its Type.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use Assembly.GetTypes() - this will get you a collection of all types and then you can get the Namespace property for each of them.

Then I guess you can simply check that all the types have same Namespace value and use this value. Otherwise add some other logic to detect what namespace to consider primary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...