Exemple #1
0
        /// <summary>
        /// Attempt to parse the string into a data kind and (optionally) a keyCount. This method does not check whether
        /// the returned <see cref="DataKind"/> can really be made into a key with the specified <paramref name="keyCount"/>.
        /// </summary>
        /// <param name="str">The string to parse.</param>
        /// <param name="dataKind">The parsed data kind.</param>
        /// <param name="keyCount">The parsed key count, or null if there's no key specification.</param>
        /// <returns>Whether the parsing succeeded or not.</returns>
        public static bool TryParseDataKind(string str, out DataKind dataKind, out KeyCount keyCount)
        {
            Contracts.CheckValue(str, nameof(str));
            keyCount = null;
            dataKind = default;

            int ich = str.IndexOf('[');

            if (0 <= ich)
            {
                if (str[str.Length - 1] != ']')
                {
                    return(false);
                }
                keyCount = KeyCount.Parse(str.Substring(ich + 1, str.Length - ich - 2));
                if (keyCount == null)
                {
                    return(false);
                }
                if (ich == 0)
                {
                    return(true);
                }
                str = str.Substring(0, ich);
            }

            if (!Enum.TryParse(str, true, out dataKind))
            {
                return(false);
            }

            return(true);
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="Column"/> class.
            /// </summary>
            /// <param name="name">Name of the column.</param>
            /// <param name="dbType"><see cref="DbType"/> of the items in the column.</param>
            /// <param name="source">Source index range(s) of the column.</param>
            /// <param name="keyCount">For a key column, this defines the range of values.</param>
            public Column(string name, DbType dbType, Range[] source, KeyCount keyCount = null)
            {
                Contracts.CheckValue(name, nameof(name));
                Contracts.CheckValue(source, nameof(source));

                Name     = name;
                Type     = dbType;
                Source   = source;
                KeyCount = keyCount;
            }
Exemple #3
0
        /// <summary>
        /// Parses the string format for a KeyCount, also supports the old KeyRange format for backwards compatibility.
        /// </summary>
        public static KeyCount Parse(string str)
        {
            Contracts.AssertValue(str);

            var res = new KeyCount();

            if (res.TryParse(str))
            {
                return(res);
            }
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Construct a <see cref="KeyType"/> out of the data kind and the keyCount.
        /// </summary>
        public static KeyType ConstructKeyType(DataKind?type, KeyCount keyCount)
        {
            Contracts.CheckValue(keyCount, nameof(keyCount));

            KeyType keyType;
            Type    rawType = type.HasValue ? type.Value.ToType() : DataKind.U8.ToType();

            Contracts.CheckUserArg(KeyType.IsValidDataType(rawType), nameof(TextLoader.Column.Type), "Bad item type for Key");

            if (keyCount.Count == null)
            {
                keyType = new KeyType(rawType, rawType.ToMaxInt());
            }
            else
            {
                keyType = new KeyType(rawType, keyCount.Count.GetValueOrDefault());
            }

            return(keyType);
        }