I heart System.Activator!
If I had to pick a single class from the wide range that the .Net framework makes available, it would have to be System.Activator. This bit of code has served me well over the years to pull off all kinds of flashy stunts that never fails to impress co-workers and clients.
Well what is it? Briefly, System.Activator can take a couple of strings as input ( along with a whole host of other invaluable overloads ) that specify an assembly name and a class, and re-constitute a fully working instantiated object from them. Impressive huh?! I’ve used it to create extendible plug-in frameworks and super configurable class libraries. Just drop a new DLL in your bin folder, and existing code that has no reference to it can instantiate and use the objects within it.
If you want a crash course on using Activator to create a plug-in architecture for your application, check out Roy Osherove’s article on the subject here.
Here’s a link to the MSDN docs. So why not make today the day that you make acquaintance of System.Activator too?
















My name is Jon Paul Davies and I work for 


August 24th, 2007 at 12:30 am
Hi, I would like to know if you could help me, it’s a cuestion about c# I’m learning to program in VB.net, but now I need to convert some code of c# into VB.net and I’m very much doubt how to understand the next code line:
AddinInfoArray[iIndex].FrameworkAddin=(IProjectFrameworkAddin)Activator.CreateInstance(AddinInfoArray[iIndex].AddinType);
what I have into VB.NET is:
AddinInfoArray(iIndex).FrameworkAddin = Activator.CreateInstance(AddinInfoArray(iIndex).AddinType)
I don’t understand what the sentence in C# does,
I will always be grateful to you for your support and thanks.
August 24th, 2007 at 8:50 am
Hi Diana, I think you are looking for the VB.NET CType Function. http://msdn2.microsoft.com/en-us/library/4×2877xb(VS.80).aspx . If i remeber my VB ( and it’s been a long time! ) your translation should be something like
AddinInfoArray(iIndex).FrameworkAddin = CType(Activator.CreateInstance(AddinInfoArray(iIndex).AddinType), IProjectFrameworkAddin)
Hope this helps!