Created
October 24, 2015 20:00
-
-
Save tmyt/86505f224e8ef4859a06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CachedValue<T> | |
{ | |
private bool _hasValue; | |
private T _value; | |
private Func<T> _getter; | |
public T Value => _hasValue ? _value : (_value = _getter()); | |
public CachedValue(Func<T> getter) | |
{ | |
_getter = getter; | |
} | |
public static implicit operator CachedValue<T>(Func<T> getter) | |
{ | |
return new CachedValue<T>(getter); | |
} | |
} | |
public class Hoge | |
{ | |
private CachedValue<bool> Is64Bit => | |
new Func<bool>(() => Marshal.SizeOf<IntPtr>() == 8); | |
// こう書きたい人生だった | |
//private CachedValue<bool> Is64Bit => | |
// () => Marshal.SizeOf<IntPtr>() == 8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment