New Posts New Posts RSS Feed: Need help with casting
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Need help with casting

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: Need help with casting
    Posted: 23-Dec-2010 at 7:45am
My code calls a Coroutine which performs a couple of queries and calculations and finally returns
 
Ideablade.EntityModel.CoRoutineOperation. Which in this case is assigned to step in the following piece of code.
 

var steps = Coroutine.Start(() => AvailableStepsSelector.RetrieveAvailableSteps(currentEvent));

steps.Completed += (sender, args) => {

if (args.CompletedSuccessfully) {

    var type = steps.Result.GetType();          // type = Ideablade.EntityModel.EntityQueryOperation [EventStepType]

    var results = steps.Result as IEnumerable<EventStepType>;  // before the assignment 25 rows --- after null

    ResetStepTypesList(results);

}

When I do a GetType() on steps.Result, I get an Ideablade.EntityModel.EntityQueryOperation [EventStepType], which is fine. On the very next line I cast steps.Result as IEnumerable<EventStepType> and the assign it to results, thinking that results will now hold the returned data. WRONG, it is null. My ultimate goal is to pass results to ResetStepTypesList where I will do the following
 
public void ResetStepTypesList(IEnumerable<EventStepType stepTypes)
{
   StepTypes.Clear();                    //StepTypes is an ObservableCollection of EventStepType
   StepTypes.ForEach(results.Add);
}
 
What am I doing wrong here between steps.Result and var results?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 23-Dec-2010 at 8:17am
If you're returning an EntityQueryOperation<EventStepType> from the Coroutine, then grab its Results -
   var op = steps.Result as EntityQueryOperation<EventStepType>;
   var results = op.Results;
 
I'm wondering why the return from the Coroutine is an EntityQueryOperation; it might be a bit simpler to return just the desired results from it, not a *Operation.
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Posted: 23-Dec-2010 at 8:19am
Can I return an observablecollection from a Coroutine?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 23-Dec-2010 at 8:22am
Yes, you can return whatever you want.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down