Print Page | Close Window

Need help with casting

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2393
Printed Date: 23-May-2024 at 5:57pm


Topic: Need help with casting
Posted By: BillG
Subject: Need help with casting
Date 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?



Replies:
Posted By: kimj
Date 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.


Posted By: BillG
Date Posted: 23-Dec-2010 at 8:19am
Can I return an observablecollection from a Coroutine?


Posted By: kimj
Date Posted: 23-Dec-2010 at 8:22am
Yes, you can return whatever you want.



Print Page | Close Window