sdk/dotnet/src/Microsoft.Datasync.Client.SQLiteStore/Utils/SqlColumnType.cs
/// <summary>
/// Serializes a value for storage into SQLite.
/// </summary>
/// <param name="value">The value to serialize.</param>
/// <param name="storeType">The SQLite store type.</param>
/// <param name="columnType">The JSON token type.</param>
/// <returns></returns>
Serializes a value for storage into SQLite.
Serializes a value for storage into SQLite .
public static object SerializeValue(JToken value, string storeType, JTokenType columnType)
        {
            if (value == null || value.Type == JTokenType.Null)
            {
                return null;
            }
            if (IsTextType(storeType))
            {
                if (columnType == JTokenType.Bytes && value.Type == JTokenType.Bytes)
                {
                    return Convert.ToBase64String(value.Value<byte[]>());
                }
                return value.ToString();
            }
            if (IsFloatType(storeType))
            {
                return value.Value<double>();
            }
            if (IsNumberType(storeType))
            {
                if (columnType == JTokenType.Date)
                {
                    var date = value.ToObject<DateTime>();
                    if (date.Kind == DateTimeKind.Unspecified)
                    {
                        date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
                    }
                    return Math.Round((date.ToUniversalTime() - epoch).TotalMilliseconds, 3);
                }
                return value.Value<long>();
            }
            return value.ToString();
        }
public static object SerializeValue ( JToken value , string storeType , JTokenType columnType ) { if ( value == null || value . Type == JTokenType . Null ) { return null ; } if ( IsTextType ( storeType ) ) { if ( columnType == JTokenType . Bytes && value . Type == JTokenType . Bytes ) { return Convert . ToBase64String ( value . Value < byte [ ] > ( ) ) ; } return value . ToString ( ) ; } if ( IsFloatType ( storeType ) ) { return value . Value < double > ( ) ; } if ( IsNumberType ( storeType ) ) { if ( columnType == JTokenType . Date ) { var date = value . ToObject < DateTime > ( ) ; if ( date . Kind == DateTimeKind . Unspecified ) { date = DateTime . SpecifyKind ( date , DateTimeKind . Utc ) ; } return Math . Round ( ( date . ToUniversalTime ( ) - epoch ) . TotalMilliseconds , 3 ) ; } return value . Value < long > ( ) ; } return value . ToString ( ) ; }
Serializes a value for storage into SQLite.
Serializes a value for storage into SQLite .
None
value
JToken
The value to serialize.
The value to serialize .
storeType
string
The SQLite store type.
The SQLite store type .
columnType
JTokenType
The JSON token type.
The JSON token type .