开发者

.NET Reflection - Getting the Assembly object instance to a Referenced Assembly

开发者 https://www.devze.com 2022-12-24 02:00 出处:网络
I have a solution called StoreExample It has one web project - StoreExample.Web It has one class library StoreExample.Core

I have a solution called StoreExample

It has one web project - StoreExample.Web

It has one class library StoreExample.Core

Web has a reference to Core. What is the proper way to get an asse开发者_如何学运维mbly reference to StoreExample.Core so I can loop over the classes in StoreExample? It seems like in LoadAssembly() method call I have to know the path to the assembly. Should I have to? If so what is the standard line of code for this? If not, what is the correct way to do it?


You should be able to use System.Reflection.Assembly.GetAssembly() as shown below:

Assembly.GetAssembly(typeof(StoreExample.Core.SomeClassInCore));


Here's a better answer if you are working with assemblies that are loaded at run time and whose type is not known at compile time. A good real-life example of this is loading 3rd party plugin modules.

http://msdn.microsoft.com/en-us/library/x4cw969y.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号