Automates the plumbing around System.Lazy
This is an add-in for Fody; it is available via NuGet:
PM> Install-Package Lazy.Fody
Your code
class Sample
{
[Lazy(LazyThreadSafetyMode.ExecutionAndPublication)]
public double Value => GetValue();
private double GetValue()
{
return 3.14;
}
}
What gets compiled:
class Sample
{
private Lazy<double> Value_lazy;
public Sample()
{
Value_lazy = new Lazy<double>(GetValue, LazyThreadSafetyMode.ExecutionAndPublication);
}
public double Value => Value_lazy.Value;
private double GetValue()
{
return 3.14;
}
}
Sloth by Chanut is Industries from the Noun Project