Microsoft.AspNetCore.SignalR.Hubs.ReflectedMethodDescriptorProvider.TryGetMethod C# (CSharp) Method

TryGetMethod() public method

Searches the specified hub">Hub for the specified In the case that there are multiple overloads of the specified method, the parameter set helps determine exactly which instance of the overload should be resolved. If there are multiple overloads found with the same number of matching parameters, none of the methods will be returned because it is not possible to determine which overload of the method was intended to be resolved.
public TryGetMethod ( HubDescriptor hub, string method, MethodDescriptor &descriptor, IList parameters ) : bool
hub HubDescriptor Hub to search for the specified on.
method string The method name to search for.
descriptor MethodDescriptor If successful, the that was resolved.
parameters IList The set of parameters that will be used to help locate a specific overload of the specified .
return bool
        public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, IList<IJsonValue> parameters)
        {
            string hubMethodKey = BuildHubExecutableMethodCacheKey(hub, method, parameters);

            if (!_executableMethods.TryGetValue(hubMethodKey, out descriptor))
            {
                IEnumerable<MethodDescriptor> overloads;

                if (FetchMethodsFor(hub).TryGetValue(method, out overloads))
                {
                    var matches = overloads.Where(o => o.Matches(parameters)).ToList();

                    // If only one match is found, that is the "executable" version, otherwise none of the methods can be returned because we don't know which one was actually being targeted
                    descriptor = matches.Count == 1 ? matches[0] : null;
                }
                else
                {
                    descriptor = null;
                }

                // If an executable method was found, cache it for future lookups (NOTE: we don't cache null instances because it could be a surface area for DoS attack by supplying random method names to flood the cache)
                if (descriptor != null)
                {
                    _executableMethods.TryAdd(hubMethodKey, descriptor);
                }
            }

            return descriptor != null;
        }