Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (backingField == null)
- backingField = SomeOperation();
- return backingField;
- public class LazyProperty<T>
- {
- private readonly Func<T> getter;
- public LazyProperty(Func<T> getter)
- {
- this.getter = getter;
- }
- private bool loaded = false;
- private T propertyValue;
- public T Value
- {
- get
- {
- if (!loaded)
- {
- propertyValue = getter();
- loaded = true;
- }
- return propertyValue;
- }
- }
- public static implicit operator T(LazyProperty<T> rhs)
- {
- return rhs.Value;
- }
- }
- first = new LazyProperty<HeavyObject>(() => new HeavyObject { MyProperty = Value });
- public HeavyObject First { get { return first; } }
- private LazyProperty<HeavyObject> first =
- new LazyProperty<HeavyObject>(() => new HeavyObject { MyProperty = Value });
- public HeavyObject First {
- get {
- return first;
- }
- }
- private HeavyObject first;
- public HeavyObject First {
- get {
- if (first == null) first = new HeavyObject { MyProperty = Value };
- return first;
- }
- }
- public Type Value
- {
- get
- {
- if(ViewState["key"] == null)
- ViewState["key"] = someDefaultValue;
- return (Type)ViewState["key"];
- }
- set{ ViewState["key"] = value; }
- }
Add Comment
Please, Sign In to add comment