Beispiel #1
0
        static T Get <T>(Dictionary <Type, Dictionary <string, Dictionary <int, T> > > dict, Type type, string name, Type[] arguments, Func <T> fetcher)
        {
            if (dict.TryGetValue(type, out var valuesByName) is false)
            {
                valuesByName = new Dictionary <string, Dictionary <int, T> >();
                dict[type]   = valuesByName;
            }
            if (valuesByName.TryGetValue(name, out var valuesByArgument) is false)
            {
                valuesByArgument   = new Dictionary <int, T>();
                valuesByName[name] = valuesByArgument;
            }
            var argumentsHash = AccessTools.CombinedHashCode(arguments);

            if (valuesByArgument.TryGetValue(argumentsHash, out var value) is false)
            {
                value = fetcher();
                valuesByArgument[argumentsHash] = value;
            }
            return(value);
        }