Class CachedAttribute
Can be used to enable caching for property. Once evaluated the property won't be recalculated until receive PropertyChanged event. It uses Fody weaving for property body replacement generation.
Inheritance
System.Object
CachedAttribute
Namespace: Eco.Core.Controller
Assembly: Eco.Core.dll
Syntax
public class CachedAttribute : Attribute
Examples
public class Sample : INotifyPropertyChanged
{
public event PropertyChangedEventHadler PropertyChanaged;
[Cached] public DateTime CachedDateTime => Date.Now;
}
// will be transformed to
public class Sample : INotifyPropertyChanged
{
public event PropertyChangedEventHadler PropertyChanaged;
DateTime? <CachedDateTime>k_Cached;
public Sample()
{
PropertyChanged += Cache_OnPropertyChanged;
}
public void Cache_OnPropertyChanged(object source, PropertyChangedEventArgs args)
{
if (args.PropertyName == "CachedDateTime") this.<CachedDateTime>k_Cached = null;
}
[Cached] public DateTime CachedDateTime => this.<CachedDateTime>k_Cached ??= Date.Now;
}
Constructors
CachedAttribute()
Declaration
public CachedAttribute()