dimanche 28 décembre 2014

Get the entire assembly in C#

I'm trying to eliminate a call from my API in which the end-user has to pass Assembly.GetExecutingAssembly() in their code, currently my code looks lke the following.



public static Dictionary<int, Packet> Packets { get; private set; }

public static void Init()
{
Assembly assembly = Assembly.GetExecutingAssembly();

foreach (Type type in assembly.GetTypes())
{
if (type.BaseType == typeof(Packet))
{
...
}
}
}


However this only gets all of the classes that are available in the API.dll, and none of the classes from the project that's using the .dll are included,


However if I pass it as a paramter, like so:



public static void Init(Assembly assembly) {}


it loads everything just fine, is this intended behaviour, is there a way to do this all in the background without the end-user ever having to worry about the Assmebly call?


In a nutshell - I have a .dll file that people will be using in their projects, I want to get all of the classes from the project that's using the .dll, not all of the classes inside of the .dll






Aucun commentaire:

Enregistrer un commentaire