/// <summary>
        /// Generates Lucene fields for the given value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="schemaField">The schema field.</param>
        /// <returns></returns>
        public static IList<Field> ToLuceneFields(this object value, Schema.Field schemaField)
        {
            if (schemaField == null)
                throw new ArgumentNullException(nameof(schemaField));

            var luceneFields = new List<Field>();  // This will contain the generated Lucene fields for the passed in value.

            var fieldName = schemaField.Name.Trim();
            var fieldDataType = GetFieldDataType(value);

            schemaField.ValidateDataType(fieldDataType);

            switch (fieldDataType)
            {
                case Schema.DataType.Number:
                    luceneFields.AddNumberField(schemaField, value);
                    break;

                case Schema.DataType.Boolean:
                    luceneFields.AddBooleanField(schemaField, value);
                    break;

                case Schema.DataType.Text:
                    luceneFields.AddTextField(schemaField, value);
                    break;

                case Schema.DataType.DateTime:
                    luceneFields.AddDateTimeField(schemaField, value);
                    break;

                case Schema.DataType.Guid:
                    luceneFields.AddGuidField(schemaField, value);
                    break;

                case Schema.DataType.Array:
                    var list = value as IList;
                    luceneFields.AddRange(list.ToLuceneFields(schemaField));
                    break;

                case Schema.DataType.Object:
                    var dictionary = value as IDictionary<string, object>;
                    luceneFields.AddRange(dictionary.ToLuceneFields(schemaField));
                    break;

                case Schema.DataType.Null:
                    luceneFields.AddNullField(schemaField);
                    break;
            }

            return luceneFields;
        }