So after looking at an article describing how to Create Object Instances Faster Than Reflection I got really excited since in my code I currently have quite a bit of reflection. Unfortunately DynamicMethod and ILGenerator are not supported in Windows CE. EDIT: Activator is supported in Windows CE
I was wondering if anyone knew of any way to create object instances faster than reflection in CE. If not, maybe someone could explain why Windows CE does not support this feature and if there are any work arounds to get this feature in CE. Even if I had to code my own DynamicMethod and ILGenerator classes it might be worth it :)
Depending on your design, you might be able to create a set of (compile-time) instantiating delegates (you can store in a static class).
For example:
This will only help if you can populate the factory in advance with the relevant types.
If all you have is a
Type(as opposed to a generic parameter), you can store delegates in aDictionary<Type, Func<object>>, although it will be less efficient due to casting.You'd still need to populate the dictionary.