Ejemplo n.º 1
0
        // REF: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Routing/Conventions/ActionRoutingConvention.cs
        // REF: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Routing/Conventions/FunctionRoutingConvention.cs
        // REF: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Routing/Conventions/EntitySetRoutingConvention.cs
        // REF: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Routing/Conventions/EntityRoutingConvention.cs
        // REF: https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData.Shared/Routing/Conventions/SingletonRoutingConvention.cs
        static bool IsActionOrFunction(IEdmEntitySet?entitySet, IEdmSingleton?singleton, string actionName, IEnumerable <string> methods)
        {
            using var iterator = methods.GetEnumerator();

            if (!iterator.MoveNext())
            {
                return(false);
            }

            var method = iterator.Current;

            if (iterator.MoveNext())
            {
                return(false);
            }

            if (entitySet == null && singleton == null)
            {
                return(true);
            }

            const string ActionMethod      = "Post";
            const string AddNavigationLink = ActionMethod + "To";
            const string FunctionMethod    = "Get";

            if (ActionMethod.Equals(method, OrdinalIgnoreCase) && actionName != ActionMethod)
            {
                if (actionName.StartsWith("CreateRef", Ordinal) ||
                    (entitySet != null && actionName == (ActionMethod + entitySet.Name)))
                {
                    return(false);
                }

                return(!IsNavigationPropertyLink(entitySet, singleton, actionName, ActionMethod, AddNavigationLink));
            }
            else if (FunctionMethod.Equals(method, OrdinalIgnoreCase) && actionName != FunctionMethod)
            {
                if (actionName.StartsWith("GetRef", Ordinal) ||
                    (entitySet != null && actionName == (FunctionMethod + entitySet.Name)))
                {
                    return(false);
                }

                return(!IsNavigationPropertyLink(entitySet, singleton, actionName, FunctionMethod));
            }

            return(false);
        }