示例#1
0
        private void CheckAndResizeBuffer(int sizeHint)
        {
            Debug.Assert(_rentedBuffer != null);

            if (sizeHint < 0)
            {
                ThrowHelper.ThrowArgumentException(nameof(sizeHint));
            }

            if (sizeHint == 0)
            {
                sizeHint = MinimumBufferSize;
            }

            int availableSpace = _rentedBuffer.Length - _index;

            if (sizeHint > availableSpace)
            {
                int growBy = Math.Max(sizeHint, _rentedBuffer.Length);

                int newSize = checked (_rentedBuffer.Length + growBy);

                T[] oldBuffer = _rentedBuffer;

                _rentedBuffer = ArrayPool <T> .Shared.Rent(newSize);

                Debug.Assert(oldBuffer.Length >= _index);
                Debug.Assert(_rentedBuffer.Length >= _index);

                Span <T> previousBuffer = oldBuffer.AsSpan(0, _index);
                previousBuffer.CopyTo(_rentedBuffer);
                previousBuffer.Clear();
                ArrayPool <T> .Shared.Return(oldBuffer);
            }

            Debug.Assert(_rentedBuffer.Length - _index > 0);
            Debug.Assert(_rentedBuffer.Length - _index >= sizeHint);
        }
示例#2
0
        public InvokeActionsDictionary(Dictionary <string, Type> controllers)
        {
            // Методы типа "home/hello" без учета регистра.
            _actionsDict = new Dictionary <string, ControllerMethodMeta>(StringComparer.OrdinalIgnoreCase)
            {
                { "/SignIn", new ControllerMethodMeta("SignIn", typeof(AccountController), AccountController.SignInMethod) },
                { "/SignOut", new ControllerMethodMeta("SignOut", typeof(AccountController), AccountController.SignOutMethod) }
            };

            foreach (KeyValuePair <string, Type> controller in controllers)
            {
                MethodInfo[] methods = controller.Value.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
                foreach (MethodInfo method in methods)
                {
                    string actionFullName = $"{controller.Key}{GlobalVars.ControllerNameSplitter}{method.Name}";
                    if (!_actionsDict.TryAdd(actionFullName, new ControllerMethodMeta(actionFullName, controller.Value, method)))
                    {
                        ThrowHelper.ThrowVRpcException($"Контроллер {controller.Value.Name} содержит несколько методов с одинаковым именем '{method.Name}'." +
                                                       $" Переименуйте методы так что-бы их имена были уникальны в пределах контроллера.");
                    }
                }
            }
        }