1

Is there a way to create a class for this kind of data?

<Condition>
    <Action/>
    <Action/>
    <Condition>
        <Action/>
        <Action/>
        <Condition>
            <Condition>
                <Action/>
            </Condition>
        </Condition>
    </Condition>
</Condition>

The data above is intrepreted as <Condition> as a Condition Object and <Action> as Action Object.

The Scenario is that the hierarchy could be till 1 .. n depth, and it could be n number of nested condition with n number of actions inside.

Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • List with [mixed types](https://stackoverflow.com/q/20133007/1997232) ? Is it allowed to have multiple conditions inside one condition? – Sinatr Aug 18 '17 at 10:17
  • Since the data has a form of tree, why not create a `Tree` class? – Dmitry Aug 18 '17 at 10:21
  • @Sinatr Thanks for showing your interest in the question. But this is not a XML this is just a way I wanted to show how my data would be nested. – Mohit S Aug 18 '17 at 10:21
  • @Dmitry I think what you are saying looks promising. Can u give me a link or something which could help me understand it well. – Mohit S Aug 18 '17 at 10:22
  • For example: https://stackoverflow.com/questions/66893/tree-data-structure-in-c-sharp – Dmitry Aug 18 '17 at 10:24

1 Answers1

0

this is not a XML this is just a way I wanted to show how my data would be nested

Then just define 2 properties:

class Condition
{
    public Condition Condition {get; set;} // different name?
    public List<Action> Actions {get; set;} 
}

how would i know which action is under what condition

You can enumerate nested structure to find it or just add parent information to each action:

class Action
{
    public Condition Parent { get; }
    public Action(Condition parent)
    {
        Parent = parent;
        parent.Actions.Add(this); // not sure if its a good idea
    }
}
Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • Then how would i know which action is under what condition. – Mohit S Aug 18 '17 at 10:52
  • See edit. That's another question, but I also often have the same problem to put all requirements into the question. Though your comments may trigger someone else's proper answer ;) – Sinatr Aug 18 '17 at 11:33