如何获取程序集的命名空间? [英] How to get Namespace of an Assembly?

查看:23
本文介绍了如何获取程序集的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个程序集(类库 dll),我使用以下代码加载了该程序集,

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");   

我需要获取大会的类型.为了获得 type 我需要程序集的命名空间.

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.

提前致谢

推荐答案

使用 Assembly.GetTypes() - 这将为您获取所有类型的集合,然后您可以获得每个类型的 Namespace 属性.

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.

这篇关于如何获取程序集的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆