I am relatively new to coding and find my best method of learning is examining existing code and were necessary deconstructing expressions into once I can more easily follow.
One of the areas I really struggle with is lambda and I appreciate it is something I will need to get my head round sooner rather than later. However I am struggling to deconstruct the following into simpler lambda free code.
private ICommand _reloadSrc;
public ICommand ReloadSourcesCommand
{
get
{
return _reloadSrc ?? (_reloadSrc = new RelayCommand(() =>
{
DataSources.Clear();
foreach (var s in _session.Select(s => new DataSourceVM { DS = s }))
{
DataSources.Add(s);
}
}, () =>
{
return _session.State > 2;
}));
}
}
What I have so far is
DataSourceVM dataSourceVM;
public ICommand ReloadSourcesCommand
{
get
{
return _reloadSrc ?? (_reloadSrc = new RelayCommand(() =>
{
DataSources.Clear();
foreach (var s in _session)
{
dataSourceVM = new DataSourceVM
{
DS = s,
};
DataSources.Add(dataSourceVM);
}
}, () =>
{
return _session.State > 2;
}));
}
}
I assume what I have done is correct as the programme still works and it appears to fit in with what I understand so far. But could anyone help converting the remainder of the code. The programme I am looking at has a number of similar expressions and I’m hoping I will be able to do the same to these once I can compare the code to some I can more easily understand.
Thank you in advance