123456789101112131415161718192021 |
- namespace Invercargill {
- public delegate T CachedGet<T>();
- private static Dictionary<int, NativeElement> cache;
- public T once<T>(owned CachedGet<T> constructor) {
- if(cache == null) {
- cache = new Dictionary<int, NativeElement>();
- }
- int location = (int)constructor;
- NativeElement<T> element;
- if(!cache.try_get(location, out element)) {
- element = new NativeElement<T>(constructor());
- cache.set(location, element);
- }
- return element.assert_as<T>();
- }
- }
|