Esempio n. 1
0
        /// <summary>
        /// Tries to retrieve method-delegate by name.
        /// </summary>
        /// <param name="itemName">The method name.</param>
        /// <param name="result">The result.</param>
        /// <returns>A value of <c>true</c> if the method was found, <c>false</c> otherwise.</returns>
        public bool TryCreateInstance(string itemName, out ReflectionHelpers.LateBoundMethod result)
        {
            lock (_nameToLateBoundMethod)
            {
                if (_nameToLateBoundMethod.TryGetValue(itemName, out result))
                {
                    return(true);
                }
            }

            if (_nameToMethodInfo.TryGetValue(itemName, out var methodInfo))
            {
                result = ReflectionHelpers.CreateLateBoundMethod(methodInfo);
                lock (_nameToLateBoundMethod)
                    _nameToLateBoundMethod[itemName] = result;
                return(true);
            }

            return(_globalDefaultFactory?.TryCreateInstance(itemName, out result) ?? false);
        }