I want to use System.Lazy to Lazy Initialization of my List in my Entites:
public class Questionary
{
private Lazy<List<Question>> _questions = new Lazy<List<Question>>(() => new List<Question>());
public IList<Question> Questions { get { return _questions.Value; } set { _questions.Value = value; } }
}
The problem is on my SETTER, get this error: The property 'System.Lazy<T>.Value
' has no setter
If i want to do MyInstance.Questions = new List<Question> { ... }
?
How do I proceed?
Update:
I'm trying to avoid that:
private IList<Question> _questions;
//Trying to avoid that ugly if in my getter:
public IList<Question> Questions { get { return _questions == null ? new List<Question>() : _questions; } set { _questions = value } }
I'm doing something wrong?