Esempio n. 1
0
        private static OperationInfo AddMethod(OperationInfo info)
        {
            if (!info.Attributes.Any(a => a is ODataOperationAttribute))
            {
                return(null);
            }

            if (info.RequiredParameterNames.Length == 0)
            {
                return(null);
            }
            if (info.RequiredParameterTypes[0] != typeof(Content))
            {
                return(null);
            }

            info.RequiredParameterNames = info.RequiredParameterNames.Skip(1).ToArray();
            info.RequiredParameterTypes = info.RequiredParameterTypes.Skip(1).ToArray();

            var operationName = IsCaseInsensitiveOperationNameEnabled ? info.Name.ToLowerInvariant() : info.Name;

            // This is a custom dynamic array implementation.
            // Reason: The single / overloaded method rate probably very high (a lot of single vs a few overloads).
            // Therefore the usual List<T> approach is ineffective because the most List<T> item will contain
            // many unnecessary empty pointers.
            if (!Operations.TryGetValue(operationName, out var methods))
            {
                methods = new[] { info };
                Operations.Add(operationName, methods);
            }
            else
            {
                var copy = new OperationInfo[methods.Length + 1];
                methods.CopyTo(copy, 0);
                copy[copy.Length - 1]     = info;
                Operations[operationName] = copy;
            }

            return(info);
        }
Esempio n. 2
0
        internal static OperationInfo AddMethod(MethodBase method, Attribute[] attributes)
        {
            var parameters = method.GetParameters();
            var req        = new List <ParameterInfo>();
            var opt        = new List <ParameterInfo>();

            foreach (var parameter in parameters)
            {
                var paramType = parameter.ParameterType;
                if (SystemParameters.Contains(parameter.ParameterType))
                {
                    continue;
                }
                if (!IsParameterTypeAllowed(paramType))
                {
                    return(null);
                }
                if (parameter.IsOptional)
                {
                    opt.Add(parameter);
                }
                else
                {
                    req.Add(parameter);
                }
            }

            var opAttr = attributes.OfType <ODataOperationAttribute>().FirstOrDefault();
            var name   = opAttr?.OperationName ?? method.Name;

            var info = new OperationInfo(name, opAttr?.Icon, opAttr?.Description, method, attributes)
            {
                RequiredParameterNames = req.Select(x => x.Name).ToArray(),
                RequiredParameterTypes = req.Select(x => x.ParameterType).ToArray(),
                OptionalParameterNames = opt.Select(x => x.Name).ToArray(),
                OptionalParameterTypes = opt.Select(x => x.ParameterType).ToArray(),
            };

            return(AddMethod(info));
        }
Esempio n. 3
0
 internal OperationCallingContext(Content content, OperationInfo info)
 {
     Content   = content;
     Operation = info;
 }