Was.OrcSearch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 1  →  ?path2? @ 2
/Was.OrcSearch/Helpers/Extensions.cs
@@ -0,0 +1,40 @@
using System;
using System.Collections;
using System.Collections.Generic;
 
namespace Was.OrcSearch.Helpers
{
public static class Extensions
{
/// <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;
 
// Base type will be string.
if (instance is string)
{
yield return (string) instance;
yield break;
}
// Support primitive types.
if (instance.GetType().IsPrimitive)
{
yield return instance.ToString();
yield break;
}
 
// Support for arrays.
if (instance is Array || instance is IList)
foreach (var element in instance as IList)
foreach (var item in Stringify(element))
yield return item;
}
}
}