Note that there are some explanatory texts on larger screens.

plurals
  1. POC# tree data structure, making output
    primarykey
    data
    text
    <p>I've made my own tree data structure via classes. Now I'm stuck with really basic stuffs. I need to make output tab delimited file from data in <em>my List <code>&lt;MainTreeNode&gt;</code></em>.<br> I think that recursion is only way?!</p> <p>Tree is N-tree, and output have first row as header and other rows are values.</p> <p><strong>Tree:</strong></p> <blockquote> <ol> <li>MSG (MainTreeNode) <ul> <li>MainParam (Must have prop NAME, doesn't have to have prop VALUE) <ul> <li>SubParam1 (Must have prop NAME, must have prop VALUE) </li> <li>SubParam2 (Must have prop NAME, doesn't have to have prop VALUE) <ul> <li>SubSubParam2.1 (Must have prop NAME, must have prop VALUE)<br> etc. </li> </ul></li> </ul></li> </ul></li> </ol> </blockquote> <p><strong>Or:</strong></p> <blockquote> <ol> <li>Message : Name <ul> <li>Param1 : ValueV1 (VALUE must, because it doesn't have children)</li> <li>Param2 <ul> <li>Param2.1 : ValueV2</li> <li>Param2.2 : Value <ul> <li>Param2.2.1 : ValueV3</li> <li>Param2.2.2 : ValueV4 ...etc.</li> </ul></li> </ul></li> </ul></li> </ol> </blockquote> <p>And output have to be like this (first line is header):</p> <pre><code>Param1|Param2/Param2.1|Param2/Param2.2/Param2.2.1|Param2/Param2.2/Param2.2.2 ValueV1|ValueV2|ValueV3|ValueV4 ... </code></pre> <p>So I need probably List for header and for values but I don't know how to implement that in recursion way (or any another).</p> <p>Some of unfinished code:</p> <pre><code>public void PrintToTabFile(List&lt;Message&gt; messages, List&lt;string&gt; parameters) { foreach (string s in parameters) { using (StreamWriter streamWriter = new StreamWriter(@"C:\temp\" + s + ".xls")) { streamWriter.Write("No.\tMsgName\tMsgData1\tMsgData2\tMsgData3"); var msg = messages.Where(x =&gt; x.Parameters.Where(p =&gt; p.ParameterName == s).Count() == 1); List&lt;string&gt; headers = new List&lt;string&gt;(); List&lt;string&gt; values= new List&lt;string&gt;(); //... Stuck!!! } } } private void Recursion(Parameter parameter, List&lt;string&gt; headers, List&lt;string&gt; values) { if (parameter.SubParameters.Count == 0) { int index = headers.IndexOf(parameter.ParameterName); values[index] = parameter.ParameterValue; } else { foreach (Parameter p in parameter.SubParameters) { Recursion(p, headers, values); //and Stuck Probably here or before recursion call } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload