.netodataodatalib

Serialize value to OData


Is there a function (perhaps in ODataLib 5.6.1) to serialize a .NET primitive type to OData URI format (see)

for instance:

new DateTime(2000,12,12).ToODataString() //would return: datetime’2000-12-12T12:00′

Solution

  • With static class Microsoft.Data.OData.Query.ODataUriUtils, you can call ConvertToUriLiteral to serialize value to uri literal.

    public static string ConvertToUriLiteral(object value, ODataVersion version)
    public static string ConvertToUriLiteral(object value, ODataVersion version, IEdmModel model)
    public static string ConvertToUriLiteral(object value, ODataVersion version, IEdmModel model, ODataFormat format)
    

    And you can call ConvertFromUriLiteral to do deserialization.

    public static object ConvertFromUriLiteral(string value, ODataVersion version)
    public static object ConvertFromUriLiteral(string value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference)