internal static object ConvertTo(string valueString, Type type)
            {
                if (valueString == null)
                {
                    return(null);
                }

                object value = ODataUriUtils.ConvertFromUriLiteral(valueString, ODataVersion.V3);

                bool isNonStandardEdmPrimitive;

                EdmLibHelpers.IsNonstandardEdmPrimitive(type, out isNonStandardEdmPrimitive);

                if (isNonStandardEdmPrimitive)
                {
                    return(EdmPrimitiveHelpers.ConvertPrimitiveValue(value, type));
                }
                else
                {
                    type = Nullable.GetUnderlyingType(type) ?? type;
                    return(Convert.ChangeType(value, type, CultureInfo.InvariantCulture));
                }
            }
Exemplo n.º 2
0
 public void ConvertPrimitiveValueToXElement_Throws_IfInputIsNotString()
 {
     Assert.Throws <ValidationException>(
         () => EdmPrimitiveHelpers.ConvertPrimitiveValue(123, typeof(XElement)),
         "The value must be a string.");
 }
Exemplo n.º 3
0
 public void ConvertPrimitiveValueToChar_Throws(string input)
 {
     Assert.Throws <ValidationException>(
         () => EdmPrimitiveHelpers.ConvertPrimitiveValue(input, typeof(char)),
         "The value must be a string with a length of 1.");
 }
Exemplo n.º 4
0
 public void ConvertPrimitiveValueToNullableChar_Throws()
 {
     Assert.Throws <ValidationException>(
         () => EdmPrimitiveHelpers.ConvertPrimitiveValue("123", typeof(char?)),
         "The value must be a string with a maximum length of 1.");
 }
Exemplo n.º 5
0
 public void ConvertPrimitiveValue_NonStandardPrimitives(object valueToConvert, object result, Type conversionType)
 {
     Assert.Equal(result.GetType(), EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, conversionType).GetType());
     Assert.Equal(result.ToString(), EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, conversionType).ToString());
 }