Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqliteColumnType"/> class.
        /// </summary>
        /// <param name="typeAffinity">The type affinity.</param>
        /// <exception cref="ArgumentException"><paramref name="typeAffinity"/> is an invalid enum value.</exception>
        public SqliteColumnType(SqliteTypeAffinity typeAffinity)
        {
            if (!typeAffinity.IsValid())
            {
                throw new ArgumentException($"The { nameof(SqliteTypeAffinity) } provided must be a valid enum.", nameof(typeAffinity));
            }

            var typeName = typeAffinity.ToString().ToUpperInvariant();

            TypeName   = typeName;
            Definition = typeName;

            DataType = _affinityTypeMap[typeAffinity];
            ClrType  = _affinityClrTypeMap[typeAffinity];
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqliteColumnType"/> class.
        /// </summary>
        /// <param name="typeAffinity">The type affinity.</param>
        /// <param name="collation">The collation.</param>
        /// <exception cref="ArgumentException"><paramref name="collation"/> or <paramref name="typeAffinity"/> are invalid enum values. Alternatively if the <paramref name="collation"/> is not <see cref="SqliteTypeAffinity.Text"/>.</exception>
        public SqliteColumnType(SqliteTypeAffinity typeAffinity, SqliteCollation collation)
            : this(typeAffinity)
        {
            if (!typeAffinity.IsValid())
            {
                throw new ArgumentException($"The { nameof(SqliteTypeAffinity) } provided must be a valid enum.", nameof(typeAffinity));
            }
            if (!collation.IsValid())
            {
                throw new ArgumentException($"The { nameof(SqliteCollation) } provided must be a valid enum.", nameof(collation));
            }
            if (typeAffinity != SqliteTypeAffinity.Text)
            {
                throw new ArgumentException("The type affinity must be a text type when a collation has been provided.", nameof(typeAffinity));
            }

            Collation = collation != SqliteCollation.None
                ? Option <Identifier> .Some(collation.ToString().ToUpperInvariant())
                : Option <Identifier> .None;
        }