|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Raven.Database.Linq.PrivateExtensions
{
/// <summary>
/// These methods allow the indexes to use Linq query syntax using dynamic
/// </summary>
public static class LinqOnDynamic
{
private static IEnumerable<dynamic> Select(this object self)
{
if (self == null)
yield break;
if (self is IEnumerable == false || self is string)
throw new InvalidOperationException("Attempted to enumerate over " + self.GetType().Name);
foreach (var item in ((IEnumerable) self))
{
yield return item;
}
}
public static IEnumerable<dynamic> SelectMany(this object source,
Func<dynamic, int, IEnumerable<dynamic>> collectionSelector,
Func<dynamic, dynamic, dynamic> resultSelector)
{
return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector);
}
public static IEnumerable<dynamic> SelectMany(this object source,
Func<dynamic, IEnumerable<dynamic>> collectionSelector,
Func<dynamic, dynamic, dynamic> resultSelector)
{
return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector);
}
public static IEnumerable<dynamic> SelectMany(this object source,
Func<object, IEnumerable<dynamic>> selector)
{
return Select(source).SelectMany<object, object>(selector);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.