summaryrefslogtreecommitdiff
path: root/code/common/FuncExtensions.cs
blob: cab3c1876af3b11cbafdd6aa9374d2321ca67ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;

namespace common
{
    static public class FuncExtensions
    {
        static readonly object mutex = new object();

        static public Func<T> memorize<T>(this Func<T> item) where T : class
        {
            T the_implementation = null;
            return () =>
            {
                if (null == the_implementation)
                {
                    lock (mutex)
                    {
                        if (null == the_implementation)
                        {
                            the_implementation = item();
                        }
                    }
                }
                return the_implementation;
            };
        }
    }
}