I have a class with a property that's a Dictionary:
public class Entity
{
public Dictionary<string, string> Name { get; set; }
}
I would like switch this property to use lazy initializtion. I tried the following:
public class Entity
{
private Lazy<Dictionary<string, string>> name = new Lazy<Dictionary<string, string>>(() => new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase));
public Dictionary<string, string> Name
{
get => name;
set => name = value;
}
}
This is of course an error, as Name and name have different types. For the life of me though, I can't figure out how to specify this correctly. All I really want is to have Name remain null until I access it, then create it on the first read or write.