[Mono-dev] System.Reflection.Assembly::Load Performance?

Leszek Ciesielski skolima at gmail.com
Wed Dec 9 10:20:30 EST 2009


On Wed, Dec 9, 2009 at 3:38 PM, Rodrigo Kumpera <kumpera at gmail.com> wrote:
>
>
> On Wed, Dec 9, 2009 at 12:00 PM, Babbage Linden <babbage at lindenlab.com>
> wrote:
>>
>> The code I'm using for loading is:
>>
>> public Script(string class_name, byte[] class_data,
>>                       ref long event_handlers)
>> {
>>             Init();
>>             Assembly assembly = Assembly.Load(class_data);
>>             foreach (Type NewType in assembly.GetTypes())
>>             {
>>                 if (NewType.IsSubclassOf(typeof(UserScript)))
>>                 {
>>                     UserScript userScript =
>>                         (UserScript)assembly.CreateInstance(
>>                             NewType.ToString());
>>
>>                     SetUser(userScript, ref event_handlers);
>>                     return;
>>                 }
>>             }
>> }
>>
>
> This loop will consume a lot of resources as the runtime have to decode and
> load all types in the assembly before returning it.
>
This foreach loop is a common pattern for loading subclasses/plugins
from an assembly, is there a better pattern for this?


More information about the Mono-devel-list mailing list