Was.OrcSearch – Rev 5

Subversion Repositories:
Rev:
using System;
using System.Collections;
using System.Collections.Generic;

namespace Was.OrcSearch.Services.Extensions
{
    public static class SearchServiceExtensions
    {
        /// <summary>
        ///     Convert an object to an enumeration of strings.
        /// </summary>
        /// <param name="instance">the object to convert</param>
        /// <returns>a series of strings</returns>
        public static IEnumerable<string> Stringify(this object instance)
        {
            if (instance == null)
                yield break;

            // Support primitive types and strings.
            var instanceType = instance.GetType();
            if (instanceType.IsPrimitive|| instance is string)
            {
                yield return instance.ToString();
                yield break;
            }

            // Support for arrays.
            if (instance is IList list)
            {
                foreach (var element in list)
                {
                    foreach (var item in Stringify(element))
                    {
                        yield return item;
                    }
                }
            }
        }
    }
}

Generated by GNU Enscript 1.6.5.90.