If the name is the same as the string, you can do something like this:
using System; using System.Reflection; class Example { static void Main() { var assemblyName = Assembly.GetExecutingAssembly().FullName; var o = Activator.CreateInstance(assemblyName, "Example").Unwrap(); } }
A simpler approach would look like this:
using System; using System.Reflection; class Example { static void Main() { var type = Assembly.GetExecutingAssembly().GetType("Example"); var o = Activator.CreateInstance(type); } }
But keep in mind that this is a very simple example that does not include namespaces, nodes with strong names, or any other complex things that arise in large projects.
source share