public static SQLiteIdList ParseString(string encodedIdList) { if (string.IsNullOrEmpty(encodedIdList)) { return(new SQLiteIdList(0)); } var match = SQLiteIdList.idListRegex.Match(encodedIdList); if (!match.Success) { throw new ArgumentException("Invalid ID list syntax: " + encodedIdList); } var captures = match.Groups[1].Captures; var idList = new SQLiteIdList(captures.Count); for (int i = 0; i < captures.Count; ++i) { idList.Add(long.Parse(captures[i].Value)); } return(idList); }
public static object ConvertSqlToObject(Type fieldType, object sqlValue) { Type nonNullableType = Nullable.GetUnderlyingType(fieldType); if (nonNullableType != null) { // If the type is nullable, then don't attempt to convert null values if (sqlValue == null || sqlValue == DBNull.Value) { return(null); } } else { nonNullableType = fieldType; } object obj; if (nonNullableType == typeof(DateTime) && sqlValue != null) { obj = DateTime.Parse((string)sqlValue); } else if (nonNullableType.IsEnum) { obj = Enum.Parse(fieldType, (string)sqlValue); } else if (nonNullableType == typeof(SQLiteIdList)) { obj = SQLiteIdList.ParseString((string)sqlValue); } else { obj = Convert.ChangeType(sqlValue, nonNullableType); } return(obj); }