11 de out de 2017

C# - instantiating a Class from String

How can we instantiate a class from a String?


string state = "BeginState";

Type type = Type.GetType("Assets.States." + state); object instance = Activator.CreateInstance(type, new object[] { stateManager }); stateManager.SwitchState((IStateBase)instance);

Nenhum comentário: