sdk/dotnet/src/Microsoft.Datasync.Client/Query/OData/EdmTypeSupport.cs
/// <summary>
/// Converts the given value to the Edm OData form, or returns null
/// if the value is not of a known type.
/// </summary>
/// <param name="value">The value to serialize</param>
/// <returns>The oData representation of the value</returns>
Converts the given value to the Edm OData form, or returns null
if the value is not of a known type.
Converts the given value to the Edm OData form or returns null if the value is not of a known type .
public static string ToODataString(object value)
        {
            long handle = (long)value.GetType().TypeHandle.Value;
            if (!TypeLookupTable.TryGetValue(handle, out EdmType type))
            {
                return null;
            }
            string result = null;
            switch (type)
            {
                case EdmType.DateTime:
                    string dt = new DateTimeOffset(((DateTime)value).ToUniversalTime()).ToString(DateTimeFormat);
                    result = $"cast({dt},Edm.DateTimeOffset)";
                    break;
                case EdmType.DateTimeOffset:
                    string dto = ((DateTimeOffset)value).ToUniversalTime().ToString(DateTimeFormat);
                    result = $"cast({dto},Edm.DateTimeOffset)";
                    break;
                case EdmType.Guid:
                    Guid guid = (Guid)value;
                    result = $"cast({guid:D},Edm.Guid)";
                    break;
            }
            return result;
        }
public static string ToODataString ( object value ) { long handle = ( long ) value . GetType ( ) . TypeHandle . Value ; if ( ! TypeLookupTable . TryGetValue ( handle , out EdmType type ) ) { return null ; } string result = null ; switch ( type ) { case EdmType . DateTime : string dt = new DateTimeOffset ( ( ( DateTime ) value ) . ToUniversalTime ( ) ) . ToString ( DateTimeFormat ) ; result = $" cast( { dt } ,Edm.DateTimeOffset) " ; break ; case EdmType . DateTimeOffset : string dto = ( ( DateTimeOffset ) value ) . ToUniversalTime ( ) . ToString ( DateTimeFormat ) ; result = $" cast( { dto } ,Edm.DateTimeOffset) " ; break ; case EdmType . Guid : Guid guid = ( Guid ) value ; result = $" cast( { guid : } ,Edm.Guid) " ; break ; } return result ; }
Converts the given value to the Edm OData form, or returns null
if the value is not of a known type.
Converts the given value to the Edm OData form or returns null if the value is not of a known type .
The oData representation of the value
The oData representation of the value
value
object
The value to serialize
The value to serialize