예제 #1
0
        private string MapType(PropertyInfo property, SqliteColumnAttribute columnData)
        {
            if (columnData.CustomBehaviour != null)
            {
                var customBehaviour = (CustomColumnBehaviour)Activator.CreateInstance(columnData.CustomBehaviour);
                return(customBehaviour.MapType(columnData, property));
            }

            var columnType = property.PropertyType;

            if (columnType == typeof(int) || columnType == typeof(long) || columnType.IsEnum)
            {
                return("integer");
            }
            if (columnType == typeof(bool))
            {
                return("bit");
            }
            if (columnType == typeof(string))
            {
                return($"varchar({columnData.Size})");
            }

            throw new NotSupportedException("Property type not supported");
        }
예제 #2
0
        private string ResolveValue(PropertyInfo property, object value, SqliteColumnAttribute columnData)
        {
            var processedValue = value;

            if (processedValue == null)
            {
                return($"NULL");
            }

            if (columnData.CustomBehaviour != null)
            {
                var customBehaviour = (CustomColumnBehaviour)Activator.CreateInstance(columnData.CustomBehaviour);
                processedValue = customBehaviour.ResolveValue(columnData, property, processedValue);
            }

            if (value.GetType().IsEnum)
            {
                return(((int)processedValue).ToString());
            }

            if (processedValue is string)
            {
                return($"'{EscapeString(processedValue.ToString())}'");
            }

            if (processedValue is bool b)
            {
                return(b ? "1" : "0");
            }

            return($"{processedValue}");
        }
예제 #3
0
 public abstract object ResolveValue(SqliteColumnAttribute columnData, PropertyInfo property, object value);
예제 #4
0
 public abstract string MapType(SqliteColumnAttribute columnData, PropertyInfo property);