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.
这篇关于如何获取程序集的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取程序集的命名空间?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01