I have the following method in a class:
public IPlayerInfo GetPlayerInfo(int playerId)
{
return GetPlayerDetails(playerId).Matches; // Matches have Runs and Wickets list
}
And I have a class as follows:
public class MyClass
{
public Lazy<IMyInterface> _service1;
public MyClass(Lazy<IMyInterface> service1)
{
_serivce1 = service1;
}
public void SomeMethod()
{
var runsList = _serivce1.GetPlayerInfo(1).Runs; // debugging this line of code
}
}
When I tried to debug the above code,
- I watched the value of
_serivce1.GetPlayerInfo(1)
using quick watch (Shift + F9
). I expanded all its child nodes. One of its child nodes isRuns
. I expandedRuns
. It showedExpanding the Results View will enumerate the IEnumerable
. I enumerated it. It was empty. - I didn't close debugging
- After sometime, when I pressed shift + F9 and viewed it again in quick watch, it had one item added after I enumerated the IEnumerable. Magic!
- After sometime, when I pressed shift + F9 and viewed it again in quick watch, it had the second item added after I enumerated the IEnumerable. Magic square!!
- Then, as
_serivce1.GetPlayerInfo(1).Runs
had two items added, instead of loading_serivce1.GetPlayerInfo(1)
and expanding the child nodeRuns
, I tried to debug_serivce1.GetPlayerInfo(1).Runs
directly but it was empty :(
When I ran without debug, _serivce1.GetPlayerInfo(1).Runs
(and so the runsList
) had no itmes at all. Please let me know if this is due to deferred execution. Also, please let me know the solution for this.