mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Missed a file in previous commit
--HG-- branch : dev
This commit is contained in:
40
src/Orchard/ContentManagement/Utilities/LazyField.cs
Normal file
40
src/Orchard/ContentManagement/Utilities/LazyField.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.ContentManagement.Utilities {
|
||||
public class LazyField<T> {
|
||||
private T _value;
|
||||
private Func<T, T> _loader;
|
||||
private Func<T, T> _setter;
|
||||
|
||||
public T Value {
|
||||
get { return GetValue(); }
|
||||
set { SetValue(value); }
|
||||
}
|
||||
|
||||
public void Loader(Func<T, T> loader) {
|
||||
_loader = loader;
|
||||
}
|
||||
|
||||
public void Setter(Func<T, T> setter) {
|
||||
_setter = setter;
|
||||
}
|
||||
|
||||
private T GetValue() {
|
||||
if (_loader != null) {
|
||||
_value = _loader(_value);
|
||||
_loader = null;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
private void SetValue(T value) {
|
||||
_loader = null;
|
||||
if (_setter != null) {
|
||||
_value = _setter(value);
|
||||
}
|
||||
else {
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user