Was.OrcSearch – Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4  
5 namespace Was.OrcSearch.Helpers
6 {
7 public static class Extensions
8 {
9 /// <summary>
10 /// Convert an object to an enumeration of strings.
11 /// </summary>
12 /// <param name="instance">the object to convert</param>
13 /// <returns>a series of strings</returns>
14 public static IEnumerable<string> Stringify(this object instance)
15 {
16 if (instance == null)
17 yield break;
18  
19 // Base type will be string.
20 if (instance is string)
21 {
22 yield return (string) instance;
23 yield break;
24 }
3 office 25  
2 office 26 // Support primitive types.
27 if (instance.GetType().IsPrimitive)
28 {
29 yield return instance.ToString();
30 yield break;
31 }
32  
33 // Support for arrays.
34 if (instance is Array || instance is IList)
35 foreach (var element in instance as IList)
36 foreach (var item in Stringify(element))
37 yield return item;
38 }
39 }
40 }