0

I have a XML schema xsd which i converted into a cs file using Xsd2Code tool in visual studio,

What I am currently doing is, // ignore syntax please as hand written

Public Method_1()
{
Fruits f = new Fruits();
f.Name = "Mangoes";

Foreach (DataRow row in DataTable)  //assume i am getting rows from database
{
      FruitsCrate fc = new FruitsCrate();
      fc.Id = 2;
      fc..... etc

      f.FruitsCrate.add(fc);  // as fruitCrate is a child node of fruit   
}

Foreach (DataRow row in DataTable)
{
      FruitBasket fb = new FruitBasket();
      fb.id = 2;
      fb....   etc

      f.FruitBaskets.add(fb);  // as fruit basket is child node
}

//a lot of more foreach just like above
}

Now problem is I want to put foreach statements in a different methods so I am not sure how can i add different childNodes to parent node,

What I am trying to do is,

Public Method_1()   //hand written code so syntax might not be right
{
   Fruits f = new Fruits();
   f = Method-2();   // ???????????????
   f = Method-3(); 
   f = Method-4(); //...........  won't f value will be reset each time
}

public Fruits Method_2(Fruits f)
{
    foreach(dataRow row in DataTable)
    {
        FruitCrate fc = new FruitCrate();
        fc.propertyA = "aaaa"; etc...

        f.FruitsCrate.add(fc);
    }
   return f;
}

2nd way of coding is hand written and I don't think will work or is even possible way

Mathematics
  • 7,314
  • 25
  • 77
  • 152
  • Indeed unclear. Try to specify what the value of `f` should be before and after the desired operation. – H H Aug 29 '13 at 10:50
  • @HenkHolterman I am trying to build up an XML file, so Fruits is a parent node (after root node) and FruitCrate is ChildNode, so each method calls for a different child node (as Fruits has different child nodes with different properties) – Mathematics Aug 29 '13 at 10:57
  • 1
    I can't see the connection between _trying to build up an XML file_ and `f = Method-2();` – H H Aug 29 '13 at 11:07
  • Are there classes derived from Fruit in the generated code? – H H Aug 29 '13 at 11:08
  • @HenkHolterman Yes these are partial classes generated by XSD2Code tool, and I also modfied my question if it helps :) – Mathematics Aug 29 '13 at 11:22
  • I can't see the connection between trying to build up an XML file and f = Method-2(); ----> because I don't know how I can add fruit with 1 child node data to other :( – Mathematics Aug 29 '13 at 11:27
  • in string we can do stringA += results.ToString(); but not sure how can i do same with XML – Mathematics Aug 29 '13 at 11:27
  • I didn't ask about partial but derived: `class Apple : Fruit`. – H H Aug 29 '13 at 11:36
  • _how can i do same with XML_ - that's not relevant anymore, you switched to classes. – H H Aug 29 '13 at 11:38
  • Maybe this is what I was looking for http://stackoverflow.com/questions/8466162/how-to-combine-a-partial-class-object-in-c – Mathematics Aug 29 '13 at 12:23

0 Answers0