/// <summary>
        /// Get the UrlKeyDelimiter in DefaultODataPathHandler.
        /// </summary>
        /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param>
        internal static ODataUrlKeyDelimiter GetUrlKeyDelimiter(this IEndpointRouteBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            return(defaultOptions.UrlKeyDelimiter);
        }
        /// <summary>
        /// Check the null dynamic property is enable or not.
        /// </summary>
        /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param>
        /// <returns>a boolean value.</returns>
        public static bool HasEnabledNullDynamicProperty(this IEndpointRouteBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            return(defaultOptions.NullDynamicPropertyIsEnabled);
        }
        /// <summary>
        /// Check the continue-on-error header is enable or not.
        /// </summary>
        /// <returns></returns>
        public static bool HasEnabledContinueOnErrorHeader(this IEndpointRouteBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            return(defaultOptions.EnableContinueOnErrorHeader);
        }
        /// <summary>
        /// Set the CompatibilityOptions.
        /// </summary>
        /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param>
        /// <param name="options">The <see cref="CompatibilityOptions"/></param>
        public static IEndpointRouteBuilder SetCompatibilityOptions(this IEndpointRouteBuilder builder, CompatibilityOptions options)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            defaultOptions.CompatibilityOptions = options;
            return(builder);
        }
        /// <summary>
        /// Sets whether or not the null dynamic property to be serialized.
        /// </summary>
        /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param>
        /// <param name="serialize"><c>true</c> to serialize null dynamic property, <c>false</c> otherwise.</param>
        public static IEndpointRouteBuilder SetSerializeNullDynamicProperty(this IEndpointRouteBuilder builder, bool serialize)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            defaultOptions.NullDynamicPropertyIsEnabled = serialize;
            return(builder);
        }
        /// <summary>
        /// Set the UrlKeyDelimiter in DefaultODataPathHandler.
        /// </summary>
        /// <param name="builder">The <see cref="IEndpointRouteBuilder"/>.</param>
        /// <param name="urlKeyDelimiter">The <see cref="ODataUrlKeyDelimiter"/></param>
        public static IEndpointRouteBuilder SetUrlKeyDelimiter(this IEndpointRouteBuilder builder, ODataUrlKeyDelimiter urlKeyDelimiter)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            if (urlKeyDelimiter == null)
            {
                throw Error.ArgumentNull("urlKeyDelimiter");
            }

            ODataOptions defaultOptions = builder.GetDefaultODataOptions();

            defaultOptions.UrlKeyDelimiter = urlKeyDelimiter;
            return(builder);
        }
        /// <summary>
        /// Configure the default services.
        /// </summary>
        /// <param name="routeBuilder">The <see cref="IEndpointRouteBuilder"/>.</param>
        /// <param name="configureAction">The configuring action to add the services to the root container.</param>
        /// <returns>A configuring action to add the services to the root container.</returns>
        internal static Action <IContainerBuilder> ConfigureDefaultServices(IEndpointRouteBuilder routeBuilder, Action <IContainerBuilder> configureAction)
        {
            return(builder =>
            {
                // Add platform-specific services here. Add Configuration first as other services may rely on it.
                // For assembly resolution, add the and internal (IWebApiAssembliesResolver) where IWebApiAssembliesResolver
                // is transient and instantiated from ApplicationPartManager by DI.
                builder.AddService <IWebApiAssembliesResolver, WebApiAssembliesResolver>(ServiceLifetime.Transient);
                builder.AddService <IODataPathTemplateHandler, DefaultODataPathHandler>(ServiceLifetime.Singleton);
                builder.AddService <IETagHandler, DefaultODataETagHandler>(ServiceLifetime.Singleton);

                // Access the default query settings and options from the global container.
                builder.AddService(ServiceLifetime.Singleton, sp => routeBuilder.GetDefaultQuerySettings());
                builder.AddService(ServiceLifetime.Singleton, sp => routeBuilder.GetDefaultODataOptions());

                // Add the default webApi services.
                builder.AddDefaultWebApiServices();

                // Add custom actions.
                configureAction?.Invoke(builder);
            });
        }