Exemplo n.º 1
0
        /// <summary>
        /// Remove the given literal prefix
        /// </summary>
        /// <param name="literalPrefix">The custom name of the literal prefix</param>
        /// <returns>'true' if the literal prefix is successfully found and removed; otherwise, 'false'.</returns>
        /// <exception cref="ArgumentNullException">Argument is null or empty</exception>
        public static bool RemoveCustomLiteralPrefix(string literalPrefix)
        {
            // Arguments validation
            ExceptionUtils.CheckArgumentStringNotNullOrEmpty(literalPrefix, "literalPrefix");

            UriParserHelper.ValidatePrefixLiteral(literalPrefix);

            // Try to remove the custom uri literal prefix from cache
            lock (Locker)
            {
                return(CustomLiteralPrefixesOfEdmTypes.Remove(literalPrefix));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a literal prefix for the given EdmType.
        /// </summary>
        /// <example>filter=MyProperty eq MyCustomLiteral'VALUE'.
        /// "MyCustomLiteral" is the literal prefix and the <paramref name="literalEdmTypeReference"/> is the type of the "VALUE".</example>
        /// <param name="literalPrefix">The custom name of the literal prefix</param>
        /// <param name="literalEdmTypeReference">The edm type of the custom literal</param>
        /// <exception cref="ArgumentNullException">Arguments are null or empty</exception>
        /// <exception cref="ArgumentException">The given literal prefix is not valid</exception>
        /// <exception cref="ODataException">The given literal prefix already exists</exception>
        public static void AddCustomLiteralPrefix(string literalPrefix, IEdmTypeReference literalEdmTypeReference)
        {
            // Arguments validation
            ExceptionUtils.CheckArgumentNotNull(literalEdmTypeReference, "literalEdmTypeReference");

            ExceptionUtils.CheckArgumentStringNotNullOrEmpty(literalPrefix, "literalPrefix");

            UriParserHelper.ValidatePrefixLiteral(literalPrefix);

            // Try to add the custom uri literal to cache
            lock (Locker)
            {
                // Check if literal does already exists
                if (CustomLiteralPrefixesOfEdmTypes.ContainsKey(literalPrefix))
                {
                    throw new ODataException(ODataErrorStrings.CustomUriTypePrefixLiterals_AddCustomUriTypePrefixLiteralAlreadyExists(literalPrefix));
                }

                CustomLiteralPrefixesOfEdmTypes.Add(literalPrefix, literalEdmTypeReference);
            }
        }