0

I'm trying to write an xml parser to take some data in a game and build out objects for me. Right now I want to go through the nodes and build out different config objects based on the node/attributes.

foreach (XmlNode node in actionList) {
  ActionConfig config;
  if (some checks determine action is "Fire") {
    config = new FireActionConfig();
    config.speed = (float)node.Attributes["speed"].Value;
  }
  // do something with config
}

The error I get is "ActionConfig does not contain a definition for speed...". I tried casting config as FireActionConfig even though it's already defined as one.

1 Answer 1

2
foreach (XmlNode node in actionList) {
    ActionConfig config;
    if (some checks determine action is "Fire") {

        FireActionConfig fireConfig = new FireActionConfig();
        fireConfig.speed = Single.Parse( node.Attributes["speed"].Value );
        config = fireConfig;
    }

    // do something with config
  }
Sign up to request clarification or add additional context in comments.

1 Comment

or in-line casting, ((FireActionConfig)config).speed = ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.