Esempio n. 1
0
        /// <summary>
        /// Registers extension method as instance method which will be included into strongly typed
        /// reflection lookup performed by <see cref="Type{T}.Method.Get{D}(string, MethodLookup, bool)"/> and related methods.
        /// </summary>
        /// <param name="method">Static method to register. Cannot be <see langword="null"/>.</param>
        public static void RegisterInstance(MethodInfo method)
        {
            var thisParam = method.GetParameterTypes().FirstOrDefault();

            if (!method.IsStatic || thisParam is null)
            {
                throw new ArgumentException(ExceptionMessages.ExtensionMethodExpected(method), nameof(method));
            }
            if (thisParam.IsByRef)
            {
                thisParam = thisParam.GetElementType();
            }
            GetOrCreateRegistry(thisParam, MethodLookup.Instance).Add(method);
        }