Пример #1
0
        /// <summary>
        /// Convert the given key value to a URI literal.
        /// </summary>
        /// <param name="value">The key value to convert.</param>
        /// <param name="keyAsSegment">Whether the KeyAsSegment convention is enabled.</param>
        /// <returns>The converted URI literal for the given key value.</returns>
        private static string ConvertKeyValueToUriLiteral(object value, bool keyAsSegment)
        {
            // For Default convention,
            //   ~/Customers('Peter') => key value is "Peter" => URI literal is "'Peter'"
            //
            // For KeyAsSegment convention,
            //   ~/Customers/Peter => key value is "Peter" => URI literal is "Peter"
            string stringValue = value as string;

            if (keyAsSegment && stringValue != null)
            {
                return(stringValue);
            }

            // All key values are primitives so use this instead of ODataUriUtils.ConvertToUriLiteral()
            // to improve efficiency.
            return(ODataUriConversionUtils.ConvertToUriPrimitiveLiteral(value, ODataVersion.V4));
        }
Пример #2
0
 private static string PrimitiveLiteral(object value)
 {
     return(ODataUriConversionUtils.ConvertToUriPrimitiveLiteral(value, ODataVersion.V4));
 }
Пример #3
0
        [InlineData(-100D, "-100.0")] // DoubleLiteralShouldHaveDecimalPointForWholeNumber
        public void ConvertToUriPrimitiveLiteralUsingPrimitiveValueWorks(object value, string expect)
        {
            string actual = ODataUriConversionUtils.ConvertToUriPrimitiveLiteral(value, ODataVersion.V4);

            Assert.Equal(expect, actual);
        }