C#反射:获取*在一个解决方案中所有*活跃的组件? [英] C# Reflection: Get *all* active assemblies in a solution?

查看:124
本文介绍了C#反射:获取*在一个解决方案中所有*活跃的组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的继承人问题:



我有2个项目 - 一个共同像拥有各类支持代码库行为的项目,实际的程序使用说,许多电话项目。我们称这些项目的通用和程序。他们都在同一个解决方案。



在通用,我对的commo反思任务的一类,如创建一个实例。如果我叫GetExecutingAssembly,它得到所有的共性的类型,但是当我用GetEntryAssembly我得到的程序类型。



虽然我当然可以编辑代码2台ASM的工作,我怕那里有比溶液刚2个项目以上的情况 - 让说5(不知道为什么,但让刚刚去那里了),我怕在调用GetExecutingAssembly和GetEntryAssembly不会得到在整个程序中的所有类型。



有没有别的东西,我可以做的就是所有类型中的解决方案的?


解决方案

 大会[] =组件AppDomain.CurrentDomain.GetAssemblies( ); 

这将得到所有加载的程序集在当前的AppDomain。



正如在评论所指出的,这是可能的,以产生多个应用程序域,在这种情况下,每个都可以有其自己的组件。最直接的优势,这样做是可以卸载通过卸载包含的AppDomain大会。


Heres my problem:

I have 2 projects - one 'common' projects with acts like a library with all kinds of support code, and the actual program that uses said project in many of its calls. We'll call these projects "Common" and "Program". They are both in the same solution.

Within "Common", I have a class for commo reflection tasks, like creating an instance. If I call GetExecutingAssembly, it gets all the "Common" Types, however when I use GetEntryAssembly I get the "Program" types.

While I certainly could edit the code to work with 2 sets of asm, I'm afraid of a situation where there are more than just 2 projects in the solution - lets say 5 (don't know why, but lets just go there for now), and I'm afraid that calling GetExecutingAssembly and GetEntryAssembly will not get all the Types in the entire program.

Is there something else that i can do to get all the Types in a solution?

解决方案

Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

This will get all of the loaded assemblies in the current AppDomain.

As noted in the comments, it's possible to spawn multiple AppDomains, in which case each can have its own assemblies. The immediate advantage to doing so is that you can unload Assemblies by unloading the containing AppDomain.

这篇关于C#反射:获取*在一个解决方案中所有*活跃的组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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