paddy

paddy

  • NA
  • 10
  • 0

LINQ to Objects Question [SOLVED]

Sep 17 2008 2:30 AM
Hi there !

I have an object, built upon a XML schema and want to use LINQ to get the data out of it
which I'm interested in :)

The structure look like the following example :

SimulationStep [1..n]
   - EnvironmentStep [1]
       - Events [0..n]
           - ResultingStateChanges [0..n]
               - Objects [1]
                   - Object[0..n]

each "Object" (the last one in that class chain) has an attribute x, y and z, meaning the position of this object
in 3D space. Theres also an ID which is used to identify each object.

Now I want to collect all (x,y,z) triplets for each SimulationStep for the object which equals the given ID.

I already tried it this way :

for (int i = 0; i < stepCount; i++)
{
    var events = from c in log.SimulationStep[i].EnvironmentSimulatorStep.EnvSimInputEvent
                        from d in c.ResultingStateChanges
                        from e in d.Agents.Agent
                       where e.id == id
                       select new { c.occurrenceTime, o = new Vector3((float)e.x, (float)e.y, (float)e.z) }
}

but all I get with this one, is the result (x,y,z) of SimulationStep 0. But I want a list with the positions
in each step. This way :

SimStep[0] - (0,0,0)
SimStep[1] - (5,0,0)
SimStep[2] - (10, 7, 0)

for example....

How to archieve that ? Many thanks in advance :)

bye and greetings :-)
paddy

Answers (1)