How to get Namespace of an Assembly?(如何获取程序集的命名空间?)
问题描述
假设我有一个程序集(类库 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.
这篇关于如何获取程序集的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取程序集的命名空间?


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01