0

Here's my XML:

<slot01>Blaster</slot01>

How do I parse this so Blaster (as a class name, NOT a string) gets added to a list such as:

List<IWeapon> weapon = new List<IWeapon>(); weapon.Add(new Blaster());

Note: my other variables are set using:

case "name": setName.Add(childList[k].InnerText.ToString()); break;

Am I missing a cast? Is what I'm trying to do even possible?

Philip
  • 43
  • 2
  • 7
  • Using reflection or using a factory, try searching. – CodeCaster Feb 23 '16 at 15:30
  • Nope, sorry, I don't see the code I require. Plus I'm not using an abstract class. – Philip Feb 23 '16 at 16:13
  • Then perhaps read harder, it might be hidden in plain sight: `Activator.CreateInstance()`. – CodeCaster Feb 23 '16 at 16:14
  • `Activator.CreateInstance()` is permanently red... monodevelop hates it. - never mind, needed to add Using System; – Philip Feb 23 '16 at 16:18
  • "Permanently red" is not an adequate problem description that we can do anything about. Perhaps consider updating your question with your current code and the actual compiler messages. – CodeCaster Feb 23 '16 at 16:21
  • Next headache...how do I pass variables using this? It seems to only accept the default constructor (which works by the way). – Philip Feb 23 '16 at 16:25
  • http://stackoverflow.com/questions/2451336/how-to-pass-parameters-to-activator-createinstancet – CodeCaster Feb 23 '16 at 16:26

0 Answers0